How to Optimize Flash Sprite Animations for Mobile
Here are some good Links to Optimize your API:
Flash to Mobile: Sprite Animation Techniques
Single Bitmap Display Object with Blitting – 8BitRocket offers some excellent tutorials on how to achieve pixel blitting within Flash. I followed these tutorials and found that their technique results in phenomenal performance within the web browser when working with simple and numerously repeated bitmap sprites. However, even with their optimized game timer loop, their technique struggles with high-resolution mobile devices like the iPad. As a simple test, I compiled their optimized game timer loop for Asteroids as an iPad app after changing the canvas size to 1024×768. The iPad’s processor struggled to redraw the game-state (running anywhere from 5-13 fps) and resulting in a very choppy asteroid game.
8Bit’s example/code: http://www.8bitrocket.com/2008/4/8/Tutorial-Creating-an-Optimized-AS3-Game-Timer-Loop/
Multiple Display Objects that Contain Bitmaps Instead of Vectors– Since I was getting the worst performance on iPad for all of my tests, I did a search for iPhone/iPad games created with Flash. There aren’t a lot out there; in fact, I found only one that included source code: Mike Chambers “Pew Pew” game, which can be found at: http://www.mikechambers.com/blog/2010/07/14/source-code-for-pewpew-released/
For optimal sprite animation performance on mobile devices, you need two things:
1) Implement the GPU vs CPU renderer for the mobile device within the publish settings. This results in the fastest bitmap manipulation, and, on the Android, also achieves a smooth, vector-like appearance on bitmaps that have been rotated.
2) Store Sprite Animations in RAM memory as BitmapData. There are two ways in Flash to manipulate bitmap data – the draw method and the copyPixels method. The draw method can convert vector data to bitmap data, but is much slower than copyPixels method (it actually runs faster in CPU render mode). The copyPixels method is the fastest and highest performing way to manipulate sprite animations, but it only works on images stored as BitmapData.
Team Color: Any turn-based or RTS game developer will undoubtedly recognize the problem of assigning unique team colors to each player’s unit. In my PC/web-based Flash version of Hero Mages, team colors are movie clip objects within the vector animations that I simply tint the color of to match the player’s color. However, bitmap data obviously does not contain any separate structures that can be manipulated this way- so how can you assign unique team colors to the optimized sprite renders? Check out Mario Klingemann’s Selective Color Replace component at http://www.quasimondo.com/archives/000614.php
Adobe’s Developer Connection for Mobile Development:
http://www.adobe.com/devnet/devices/fpmobile.html
Android AIR Optimization Techniques:
http://www.unitedmindset.com/jonbcampos/2010/09/08/optimization-techniques-for-air-for-android-apps/
Found that in this Forum:
http://www.kirupa.com/forum/showthread.php?p=2594452#post2594452
Thanks for the link. We are in the process of evaluating how to best build mobile apps with flash and other technologies. Ir is true that many of our old stand-by techniques simply do not work on the iPhone. We hope to have some good stuff to talk about very soon.
I’m trying desperately to get a flash game functioning on an Android Galaxy Tab before the flash gaming summit and Game Dev Conf in San Francisco. My game is quite complex and the performance is terrible on the mobile device. I am experimenting with cacheAsBitmapMatrix but the gains are either negligible or performance actually suffers. I am going to try porting the game as a native android app and hopefully I will see huge performance gains.
We use a system which renders every frame of an animation to separate BitmapData (NOT an all-in-one sheet but each frame a seperate render), stores it in a centralized manager, and then pass references to those frame-data’s to one or more Bitmap’s for display (offset per frame).
This is optimal in memory (the frames have no padding like in spritesheets, thanks to getBounds()), and there’s no heavy-duty pixel block memory operations involved like with blitting, just updating some references and let Flash take care of the rest. You can layer in loads of cool stuff once you have the basic system running.