Here's the code for the time-based animation. The sprites are identical to 
the frame-based behavior, but I set the tempo to 1 fps in frame 1.

First, the behavior attached to the "master" sprite:

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) ]
   timeout("bounceTime").new(17, #moveMe, me)
end

--=============================
on moveMe
   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 )
   sendAllSprites(#moveUs)
   updateStage
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

and the behavior attached to the other 29 sprites:

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 moveUs
   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