SHARE
TWEET

Managing Animation State in GameObjects

ulfben Jan 26th, 2016 (edited) 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     This is an example of the simplest solution I can think off.
  3.     My question is: are there any good standard solutions / practices / patterns
  4.         to deal with animation states? Especially as they get more complex than two states
  5.         I imagine this solution being way too unwieldy to maintain.
  6.  
  7.  
  8.     _idleAnimation and _turnAnimation are both members of the GameObject,
  9.         and children of its DisplayList.
  10. */
  11. private function updateAnimationState(dx:Number):void
  12. {
  13.     if(Math.abs(dx) < 4)
  14.     {
  15.         start(_idleAnimation);
  16.         stop(_turnAnimation);  
  17.     }
  18.     else
  19.     {
  20.         stop(_idleAnimation);
  21.         start(_turnAnimation);
  22.         _turnAnimation.scaleX = (dx < 0) ? 1 : -1; //flip left/right
  23.     }
  24. }
  25.  
  26. //EDIT: http://gamedev.stackexchange.com/questions/27079/data-driven-animation-states seems like a well researched comment
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top