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
Scroll Text With Mouse
Eat That Dot
OnStage DVD for Director
Set Rotation angle of a Flash Member
Change bitmap brightness and contrast behaviour
Graphic Drag on top
Play Soundfile
Sprite Group Movement behavior
Toggle ActionsEnabled Property of a Flash Member
Movable Hole with Mask Ink
 

 

 

Behavior Rolling Ball

Added on 9/6/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: MediaMacros (website)

This behavior can be dropped on a bitmap ball to make it roll across a plane.

--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
property spriteNum, diameter, baseH, constraintSprite

on getPropertyDescriptionList me
  p_list = [:]
  p_list.addProp(#constraintSprite, [#format : #integer, #comment : "Sprite to roll on:", #default : (the currentSpriteNum + 1)])
  return p_list
end

on beginSprite me
  diameter = sprite(spriteNum).height
  baseH = sprite(spriteNum).locH
end

on mouseDown me
  startMouseH = the mouseH
  startSpriteH = sprite(spriteNum).loch
  repeat while the stillDown
    hOffset = the mouseH - startMouseH
    newLocH = startSpriteH + hOffset
    if newLocH < sprite(constraintSprite).left then
      newLocH = sprite(constraintSprite).left
    else if newLocH > sprite(constraintSprite).right then
      newLocH = sprite(constraintSprite).right
    end if
    --get the rotation
    percentage = (newLocH - baseH) / (diameter * pi)
    sprite(spriteNum).rotation = 360 * percentage
    sprite(spriteNum).locH = newLocH
    updateStage
  end repeat
end

on getBehaviorDescription me
  return "This is a simple behavior for rolling a ball along a flat surface. Drop it on the bitmap sprite for the ball and assign the constraint sprite."
end

 


Contact

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

Send e-mail