Use on sprites to make them rotate around a given point.
-- Rotate-a-Sprite
-- use on sprites to make them rotate around a given point
-- the radius is calculated by the sprite"s distance from
-- the center point. Speed and direction is adjustable.
-- by dirk eismann, d.eismann@medienkonzepte.de
-- the distance from the center
x = pCenter[1] - pSprite.loc[1]
y = pCenter[2] - pSprite.loc[2]
-- get the radius
pRadius = sqrt((x*x)+(y*y))
-- angle towards the center
pRad = atan(-x,-y)
-- how the sprite moves
if pDir = #left then
pDpF = pDpF * pi / 180.00
else
pDpF = - pDpF * pi / 180.00
end if
end beginSprite
on exitFrame me
-- add the per-frame change to the current rad-value
pRad = pRad + pDpF
-- update the sprite"s position
pSprite.loc = point(pRadius * sin(pRad),pRadius * cos(pRad)) + pCenter
end exitFrame
on getPropertyDescriptionList
description = [:]
description.addProp(#pCenter,[#comment:"Rotate around point:",#format:#point,#default:point(100,100)])
description.addProp(#pDpF,[#comment:"Speed (degrees per frame):",#format:#integer,#range:[#min:1,#max:360],#default:1])
description.addProp(#pDir,[#comment:"Direction:",#format:#symbol,#range:[#left,#right],#default:#right])
return description
end getPropertyDescriptionList
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA