ulfben

Managing Animation State in GameObjects

Jan 26th, 2016
128
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×