Flash Truth

…about flash gamedev and business

Time based vs Frame based

This topic pops up from time to time. Usualy because someone is having a hard time in getting his game flowing decently. Flash is so accessible that even the most obvious things done time and time again for more seasoned developers escapes the grasp of the vast majority of new developers.

“Stop the bla bla bla and get to business” says the little voice in my head! Ok! The problem is the use of ENTER_FRAME events. Games live off these events and those are used and abused without any care. Here are some rules to have your game running smoothly and frame rate independent.

Use only one ENTER_FRAME event

You should have only one ENTER_FRAME event. This should act as your game loop. If you have several events, you will have several game loops and not only this can be a CPU hog, but it can generate logic inconsistencies.

Having one game loop for ALL the game can be quite a challenge for a less experience developer, so I would adivse you to start with having one ENTER_FRAME event where it matters, for instance, on a movie clip that holds the levels, but your ambition should be to have one and only one game loop that holds a list of what it has to update.

Use delta times

Delta time is the difference between the last rendering and the current rendering. Write classes that take delta time into consideration. The main difference is that if you have a sprite that moves 5 pixels per frame, if the frame rate changes, so will the number of pixels the sprite moves per second. What you want to achieve is the exact opposite. Regardless of the frame rate, the sprite moves the a number of pixels per second.

Remember to remove your listeners

This is too easy to forget! When you don’t have the use for the events, remove the listeners! Even if you remove a movie clip from stage, the listeners will be active, thus bringing up the problem of multiple game loops and inconsistencies.

Hope this helps! Have fun!

November 18, 2008 Posted by | Technical | , , , , , | 6 Comments