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 | , , , , ,


  1. Hey, no comment for the post itself but I happened upon the blog in a google search and I’ve got to say I really like it so far – keep it up!

    Comment by TheSidehatch | November 19, 2008 | Reply

  2. Thanks! Hope you get back here often and remember… TELL YOUR FRIENDS! 🙂

    Comment by flashtruth | November 19, 2008 | Reply

  3. Hey Flashtruth (or is it Andreas? Look at the bottom of the page to see where Chris got that from)

    I’m really impressed with your blog too. I only just discovered it whilst looking through my blog stats (Drastika) and noticed a link from here.

    I’ve just gone through and read all of your posts – very good content. I’ll be adding your site to my blog roll when I get a spare minute.

    I have a feeling that we may have had contact over at FGL, but my memory escapes me.

    Anyway, keep up the good work.


    Comment by pault107 | December 11, 2008 | Reply

  4. Ah! Andreas is the guy that made the template. Glad you are enjoying the blog, been having a hard time getting some traffic, was wondering it wasn’t appreciated.

    Comment by flashtruth | December 11, 2008 | Reply

  5. thanks very much for this article. it optimized the hell out of my app.

    Comment by jim | December 17, 2008 | Reply

    • Glad it helped! I’m wondering what other technical things I should post about. Any ideas?

      Comment by flashtruth | December 19, 2008 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: