Here's the behavior attached to the frame-based animation. Again, credit 
for the basic concept goes to Robert Wingate--I just made minor tweaks.

There are 30 bitmap sprites, all with the same behavior attached. 18 of 
them use Copy ink, and the 12 red circles use Background Transparent. The 
sprite spans are all 1 frame, in the second frame. In the first frame I set 
the tempo to 60 fps.

property fUseStage
property kSpeed, kBound, spriteNum
property kLimitL, kLimitT, kLimitR, kLimitB
property iDirH, iDirV

--=============================
on beginSprite me
   w2 = sprite(spriteNum).width / 2 + 1
   h2 = sprite(spriteNum).height / 2 + 1

   -- set boundaries
   if fUseStage then
     rStage = (the stage).rect
     kStageWidth = rStage.right - rStage.left
     kStageHeight = rStage.bottom - rStage.top
     kLimitL = w2
     kLimitT = h2
     kLimitR = kStageWidth  - w2
     kLimitB = kStageHeight - h2
   else
     kLimitL = sprite(kBound).left + w2
     kLimitT = sprite(kBound).top  + h2
     kLimitR = sprite(kBound).right  - w2
     kLimitB = sprite(kBound).bottom - h2
   end if

   iDirH = [ kSpeed,-kSpeed ][ random(2) ]
   iDirV = [ kSpeed,-kSpeed ][ random(2) ]
end

--=============================
on exitFrame
   curH = sprite(spriteNum).locH
   curV = sprite(spriteNum).locV

   if ( curH < kLimitL ) or ( curH > kLimitR ) then iDirH = -iDirH
   if ( curV < kLimitT ) or ( curV > kLimitB ) then iDirV = -iDirV

   sprite(spriteNum).loc = point( curH,curV ) + point( iDirH,iDirV )
end

--=============================
on getPropertyDescriptionList
   def = the currentSpriteNum - 1
   ls = [:]
   ls.addProp( #fUseStage, [ #comment:"Use stage as bounding rect",�
               #format:#boolean, #default:FALSE ])
   ls.addProp( #kBound, [ #comment:"Bounding rect sprite:",�
               #format:#integer, #default: the currentSpriteNum - 1 ])
   ls.addProp( #kSpeed, [ #comment:"Bounce Speed:", #format:#integer,�
               #range:[#min:1,#max:10], #default:1 ])
   return ls
end


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to