Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
DirectConnection
Frogger by J.R.D.R.
Date Time Xtra
Sound slider
PDF Asset Xtra
KK
RC4 Encryption Algorithm Script
Simple projectile with gravity
Check QuickTime Version
ProFusion Xtra for Authorware and Director
 

 

 

Behavior Super Goo

Added on 6/22/2000

 

Compatibilities:
behavior D8 Mac PC Shockwave

This item has not yet been rated

Author: DaveMennenoh

Attach this behavior to a bitmap sprite this behavior uses one Global variable: newImage that is an image object that keeps a copy of each new image loaded in it used with the Revert button

Download PC Source    Download Mac Source
--DGoo 1.0
--Dave Mennenoh 2000
--dmennenoh@gessert.com

--Attach this behavior to a bitmap sprite
--this behavior uses one Global variable: newImage that is an image object
--that keeps a copy of each new image loaded in it used with the Revert button

property spriteNum
property r1Image,r2Image,r3Image,r4Image
property originalImage,undoImage,originalRect

--grab a copy of the original bitmap and its rect so we can use the original button
on beginSprite me
  originalImage=sprite(spriteNum).member.image.duplicate()
  originalRect=sprite(spriteNum).rect
end

--on end set the sprite back to it's original state
on endSprite me
  sprite(spriteNum).member.image=originalImage
end

--if newImage exists then revert back to it- otherwise revert to the original
on revert me
  global newImage
  if objectP(newImage) then
    sprite(spriteNum).member.image=newImage
  else
    sprite(spriteNum).member.image=originalImage
  end if
end

--set the sprite to it's undo image
--undo image is set at the beginning of mouseDown
on undo me
  if objectP(undoImage) then
    sprite(spriteNum).member.image=undoImage
  end if
end

--set the sprite back to it's original image and rect
--set newImage and undoImage to zero
on original me
  global newImage
  sprite(spriteNum).member.image=originalImage
  sprite(spriteNum).rect=originalRect
  newImage=0
  undoImage=0
end

on mouseDown me
  global distRange
  undoImage=sprite(spriteNum).member.image.duplicate()
  upperLeft=point(sprite(spriteNum).left,sprite(spriteNum).top)
  fromCursor=distRange/2
  mPoint=the mouseLoc
  memPoint=mPoint-upperLeft --gives us the click loc in the member
  
  --Check to ensure the edges of the retange we grab don't lie outside the
  --extents of the image
  mMinFrom1=memPoint[1]-fromCursor
  if mMinFrom1<0 then mMinFrom1=0
  mMinFrom2=memPoint[2]-fromCursor
  if mMinFrom2<0 then mMinFrom2=0
  mPlFrom1=memPoint[1]+fromCursor
  if mPlFrom1>sprite(spriteNum).member.rect[3] then mPlFrom1=sprite(spriteNum).member.rect[3]
  mPlFrom2=memPoint[2]+fromCursor
  if mPlFrom2>sprite(spriteNum).member.rect[4] then mPlFrom2=sprite(spriteNum).member.rect[4]
  
  --define original rects around cursor click point
  --these rects are in member coords
  r1=rect(mMinFrom1,mMinFrom2,memPoint[1],memPoint[2])
  r2=rect(memPoint[1],mMinFrom2,mPlFrom1,memPoint[2])
  r3=rect(memPoint[1],memPoint[2],mPlFrom1,mPlFrom2)
  r4=rect(mMinFrom1,memPoint[2],memPoint[1],mPlFrom2)
  
  --create new images based on the above rects
  r1Image=image(r1[3]-r1[1],r1[4]-r1[2],32)
  r2Image=image(r2[3]-r2[1],r2[4]-r2[2],32)
  r3Image=image(r3[3]-r3[1],r3[4]-r3[2],32)
  r4Image=image(r4[3]-r4[1],r4[4]-r4[2],32)
  
  --now copy pixels from the member into the new images
  mI=sprite(spriteNum).member.image
  r1Image.copyPixels(mI,r1Image.rect,r1)
  r2Image.copyPixels(mI,r2Image.rect,r2)
  r3Image.copyPixels(mI,r3Image.rect,r3)
  r4Image.copyPixels(mI,r4Image.rect,r4)
  
  repeat while the stillDown
    x=the mouseLoc-upperLeft --current pos in the member
    
    if x[1]>r1[1] and x[1]r1[2] and x[2]      
      r1Quad=[point(r1[1],r1[2]),point(r1[3],r1[2]),the mouseLoc-upperLeft,point(r1[1],r1[4])]
      r2Quad=[point(r2[1],r2[2]),point(r2[3],r2[2]),point(r2[3],r2[4]),the mouseLoc-upperLeft]
      r3Quad=[the mouseLoc-upperLeft,point(r3[3],r3[2]),point(r3[3],r3[4]),point(r3[1],r3[4])]
      r4Quad=[point(r4[1],r4[2]),the mouseLoc-upperLeft,point(r4[3],r4[4]),point(r4[1],r4[4])]
      
      sprite(spriteNum).member.image.copyPixels(r1Image,r1Quad,r1Image.rect)
      sprite(spriteNum).member.image.copyPixels(r2Image,r2Quad,r2Image.rect)
      sprite(spriteNum).member.image.copyPixels(r3Image,r3Quad,r3Image.rect)    
      sprite(spriteNum).member.image.copyPixels(r4Image,r4Quad,r4Image.rect)
      
      updateStage
    end if
  end repeat
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail