Thursday, March 13, 2008

Centralized update

When you get into game programming, the first thing you learned is that you should use a centralized update function triggered by your onEnterFrame event or Timer (AS3)/setInterval (AS2) event that in turns call game objects update. There are many benefits in having a single point of entry for update - one is performance and another reason is you want the ability to control what game objects receive update and when. For example, when you are pausing the game, all you need to do is one line of conditional statement in your root level update function to ensure all child level update functions stop getting called.

Multiple gotoAndPlay considered really harmful

Shortly after I wrote a blog post about how decentralized gotoAndPlay calls can mess up your game states, I ran into a situation where calling gotoAndPlay on the same clip multiple times is causing real harm! Basically, I have a hit animation on an enemy movieclip that gets played whenever the enemy is hit. For enemies that can take multiple hits before they are destroyed, they sometimes would run into a "stuck" state where the animation isn't playing anymore. Finally, I had to fix it by making sure that the hit state animation can only be played when it's done playing. This has not been the case for many other game projects I have done, so I am not sure exactly what combination of things are causing this behavior.