Flash Mobile Drawing Performance: The Best Way?

I’ve read a lot of posts about how to get the best performance when rendering/drawing using Adobe AIR for mobile.  Some claim using Sprites and setting cacheAsBitmap and cacheAsBitmapMatrix is the key.  Others claim that drawing all graphics to a single Bitmap is the way to go.

Surprisingly, I haven’t read anything about the method I’ve often found to provide the best performance: using graphics.drawRect().  Yes, my tests on multiple handsets (including the Motorola Droid and HTC Evo) have suggested that I get a roughly 50% better frame rate when I use a single Shape object to draw all the objects/layers of my game.

There are several items to note about this approach:

  • don’t use this approach for drawing static backgrounds that never change
  • generate BitmapData for all graphics before starting the game/level
  • creating or modifying BitmapData during the game loop is very, very expensive — try your best never to do this
  • call ‘graphics.clear’ each frame before drawing to the Shape to avoid remnants from previous game loop cycles
  • use ‘graphics.beginBitmapFill’ followed by ‘graphics.drawRect’ to draw on the Shape every frame
  • minimize # of Shape objects — I usually can get away with one, but I’m sure there are some potential efficiencies to be gained from more complex systems with dirty flags
  • use pools if you have to regularly instantiate any type of object — instantiation of objects can be very expensive & is often unnecessary

Using the Graphics object has been very successful for me but I want to say that I’m absolutely sure this is not the best solution in every scenario.  Try each of the different approaches you’ve read about and see what works for you and your game.  Another solution can be found here.

*Update: further tests have suggested this approach definitely performs well but in very specific scenarios — read our Using Graphics in Small Doses article for more.

For more articles like this, news, tutorials, trends and more follow us on Twitter.

Share:
  • Twitter
  • Digg
  • Yahoo! Buzz
  • Reddit
  • StumbleUpon
  • del.icio.us
  • Mixx
  • FriendFeed
  • Technorati
  • Facebook
  • RSS

5 Comments

  1. Jake says:

    Hey now, thats a great idea! Thanks much for sharing. The next time I get a bit of free time, I might try dropping that method into the Sheep Drawing Test as another option, assuming thats cool with you…

    Thanks again!

    • admin says:

      Yeah, I’d be really interested to see how this approach compares to those in your tests. If you’d drop a line when you get around to that, I’d appreciate it.

      Thanks

      • Jake says:

        I just hacked in the translation portion of using the BitmapFill/Fillrect method… but I’m not getting the results I expected… any chance you can send me an email? I want to make sure that I’m implementing it the same way you did.

        Thanks!
        Jake

  2. [...] This post was mentioned on Twitter by Eric Snowden. Eric Snowden said: Flash Mobile Drawing Performance: The Best Way? http://goo.gl/fb/mUXcw [...]

  3. [...] This is an update from the original article Flash Mobile Drawing Performance: The Best Way? [...]

Leave a Comment

Please leave these two fields as-is: