Friday, July 22, 2011

Flash Game Dev Tip #10 – Flixels Internal Structure and Performance Tips

Flixels Internal Structure and Performance Tips

Tip #10 – Flixels Internal Structure and Performance Tips

If you’ve ever wondered just what Flixel does when it starts-up or runs its main loop, then wonder no more :) Here’s the full gory details, with some take-away performance tips at the end.

The Instantiation Process

All games in Flixel extend the FlxGame class, which in turn extends Sprite. When the game is created the following process happens, in the following order:

  1. It hides the system mouse cursor
  2. Calls FlxG.init which clears the bitmap cache, creates a new Sprite (flashGfxSprite) and creates an empty cameras Array
  3. Sets the internal game frame rate
  4. Sets the Flash Player frame rate
  5. Adds an ENTER_FRAME Event Listener which triggers FlxGame.create

Frame rates

Flixel 2.5 uses a Deterministic Delta Timer to handle steps within the framework. A step (as you’ll see later) is processed in the main loop, and is when Flixel performs all of the collision, separation and movement calculations. This is not the same thing as when it renders the game. When you create your game you have to tell FlxGame what game frame rate and Flash Player frame rates you want. From these two values it does the following:
  • Sets the step to be 1000 / Game Frame Rate. So a rate of 30 updates per second would equal a step of 33.
  • Sets the Maximum Accumulation (maxAcc) value to 2000 / Flash Player Frame Rate (fps) – 1.
  • So an fps rate of 30 would equal a maxAcc of 66. The maxAcc can never be less than step.
Read more: Flash Game Dev Tip #10 – Flixels Internal Structure and Performance Tips

No comments:

Post a Comment