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