Flip Sprite - Make a sprite appear to rotate in 3-D space.
Added on 7/30/2002
Compatibilities:
This item has not yet been rated
This behavior makes a sprite appear to rotate in 3-D space around the Y-axis of the screen. The perspective illusion can be adjusted, as well as the speed of "flippage." Makes a fun visual effect.
-- Behavior by Ken Loge - kenl@ori.org
-- Special thanks to Aaron Cram for the algorithm
-- Version 1.0
-- 05-05-01
property pAngle
property pOriginalQuad -- original quad of the sprite
property pSpriteQuad -- the quad of the sprite at any given moment of change
property pSpriteWidth
property pSpriteHeight
property pXl -- use for quad offset
property pXr
property pYl
property pYr
property pFlipSpeed -- speed of rotation 1=slow, 100=fast negative=opposite direction
property pPerspective -- perspective illusion, 0=orthographic, 20=normal
on beginSprite me
-- initialize values for float math
pAngle = 0.0
pXl = 0.0
pXr = 0.0
pYl = 0.0
pYr = 0.0
-- get initial sprite values
pOriginalQuad = sprite(me.spriteNum).quad
pSpriteWidth = sprite(me.spriteNum).width
pSpriteHeight = sprite(me.spriteNum).height
end
on getBehaviorDescription me
return "Flips a sprite continuously around the Y axis with a 3-D perspective illusion."
end
on getPropertyDescriptionList me
list = [:]
addProp list, #pFlipSpeed, [#comment: "Flip Speed:", #format: #integer, #default: 10, #range: [#min: -100, #max: 100]]
addProp list, #pPerspective, [#comment: "Perspective Factor:", #format: #integer, #default: 20, #range: [#min: 0, #max: 50]]
return list
end
on exitFrame me
-- changing the cos() functions below to sin() and
-- the sin() functions to cos() reverses the direction of rotation
pSpriteQuad = sprite(me.spriteNum).quad
-- there's probably a much more elegant way to do the following, but it works
pXr = pSpriteWidth / 2
pXl = pSpriteWidth / 2
pXr = pXr * cos(pAngle)
pXl = pXl * cos(pAngle + 3.14)
pSpriteQuad[1].locH = pXl + sprite(me.spriteNum).loc[1]
pSpriteQuad[2].locH = pXr + sprite(me.spriteNum).loc[1]
pSpriteQuad[3].locH = pXr + sprite(me.spriteNum).loc[1]
pSpriteQuad[4].locH = pXl + sprite(me.spriteNum).loc[1]