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
EZIO
Simple Sprite Mover Behavior
Res Mode
RotateWithSound
Version
Kaboom!
RavWare OpenGL Xtra
Dean's Director Resources
Vector Shape - Create Sine Wave
Set Volume - Buddy API
 

 

 

Behavior Flip Sprite - Make a sprite appear to rotate in 3-D space.

Added on 7/30/2002

 

Compatibilities:
behavior D8 D8_5 D9 Mac PC Shockwave US

This item has not yet been rated

Author: kenl (website)

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]

  pYr = sin(pAngle) * pPerspective
  pYl = sin(pAngle + 3.14) * pPerspective
  pSpriteQuad[2].locV = pOriginalQuad[2].locV - pYr
  pSpriteQuad[3].locV = pOriginalQuad[3].locV + pYr
  pSpriteQuad[1].locV = pOriginalQuad[1].locV - pYl
  pSpriteQuad[4].locV = pOriginalQuad[4].locV + pYl

  sprite(me.spriteNum).quad = pSpriteQuad

  if pAngle > 6.28 then pAngle = 0
  if pAngle < 0 then pAngle = 6.28
  pAngle = pAngle - pFlipSpeed / 100.0
end

 


Contact

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

Send e-mail