Getting high FPS on Flash/AIR games for mobile?

05/09/2012 10:07#1

Bruno G.


Joined at: 8 months ago

Post: 1

Thank: 0

Thanked: 0

I'm working on a game aimed to be deployed on mobiles as "native" apps, and desktop web browsers.

Since working on several platforms, Flash and its embedded AIR seemed to be a pretty good solution. But uh-oh.

Working only for now with 4-keyframed movieclips (Adding them to stage, updating their position on every frame, and eventually removing them) makes the game to slow down when about 30 are displayed on desktop screen, about 20 when displayed on my Android (Samsung i9000 - 2.3.3). And I may need more.

So I tried blittering, by redrawing regions of my bitmap, and converting my MovieClips to bitmapDatas spritesheets, stored in my Flash library. Results on desktop are great, with perfect, smooth animations, even with hundreds of objects. But the result on mobile is terrible, FPS drops down to 15 even when only one object is displayed on screen, CPU or GPU rendered.

Because it would obviously be nice that my game works on 'old' devices, is working with Flash and AIR a bad idea at this time if I want to reach a framerate close to or above 50 ?

Is there any tips, or indispensable practices that needs to be used when developping a mobile game with flash ? Is there any common mistakes we have to avoid in these kinds of case ?

05/09/2012 10:49Top#2



Joined at: 12 months ago

Post: 34

Thank: 0

Thanked: 0

You can get some improvement with cacheAsBitmap and cacheAsBitmapMatrix, in combination with GPU rendering, but chances are that still won't get you anywhere near 60fps for anything remotely complex.

If you want real performance on mobile devices you'll probably want to check out Starling framework ( It completely moves compositing and rendering to the GPU, while keeping object model and display list pretty close to standard Flash equivalents. Performance is blazing fast (60fps easily achievable), even on generation or two old hardware.

15/03/2016 00:58Top#3

Joined at: 11 months ago

Post: 2

Thank: 0

Thanked: 0

You actually can get 30fps to 50fps in Adobe Air with very complex Flash vector animations.

What not to do:

  1. Don't use the pre-made "Cache as bitmap" checkbox for anything animated. This is a great feature when applied to static vector images, as it converts it to a static bitmap. If the animation is animated in any way other than translating the movie clip on x or y axis, your animation will actually be SLOWER with cache as bitmap turned on.

  2. Don't do blitting. Blitting can make games blazing fast in Flash, but on Adobe air it makes them slower. What you want is a bitmap Object placed on the stage, not a bitmapData object being blitted onto the stage.

So, what you CAN do to is grab a swf or Movieclip, and run though every frame of the object and convert each frame to a bitmap. Then, save each bitmap into an array. Then, to play the animation, retrieve the bitmaps from the array and place them sequentially on the stage. In my tests, I am able to run a full screen, 24 frame animation on an Android tablet at over 40fps.

Code sample follows. It will cache the bitmaps slowly, finish, and then immediately start playing at a much higher rate. If desired, you an hide the animation while it caches. Clear the array to free up memory when you don't need the animation anymore.

package scripts.animation{     import flash.display.MovieClip;     import*;     import flash.display.Stage;     import flash.display.Bitmap;     import flash.display.BitmapData;     import flash.display.*;     import;       public class spriteSheetMaker extends MovieClip {         private var pWidth:int=0;         private var pHeight:int=0;         private var regX:int=0;         private var regY:int=0;         private var swfObj:MovieClip = null;         private var pFrame:int=0;         private var pFrames:int=0;         private var pSheetArray:Array=[];         private var pSheetInfo:Array=[];         private var pAnimating:Boolean = false;         private var pAnimationCycle:int = 0;         //-------------------------------------------------------         //-------------------------------------------------------         //init         //-------------------------------------------------------         //-------------------------------------------------------         public function spriteSheetMaker ():void {             startGrab();         }         //-------------------------------------------------------         //-------------------------------------------------------         //swf is loaded, find out how many frames are in, dimentions etc, and start animation         //-------------------------------------------------------         //-------------------------------------------------------         public function startGrab ():void {             swfObj=this.animation;             swfObj.x = 0;             //swfObj.y = 0;             pFrames=swfObj.totalFrames;             pFrame=0;             pSheetInfo=[,pWidth,pHeight];             pSheetArray.push (pSheetInfo);             pAnimating = false;             this.addEventListener (Event.ENTER_FRAME,cycleSwfAnim);         }         //-------------------------------------------------------         //-------------------------------------------------------         //load the next frame of the animation and convert it         //-------------------------------------------------------         //-------------------------------------------------------         private function cycleSwfAnim (event:Event):void {             pFrame++;             if (pFrame < pFrames + 2) {                 swfObj.gotoAndStop (pFrame);                 grabBitmap ();             } else {                 stopGrab ();             }         }         //         private function stopGrab():void{             this.removeEventListener (Event.ENTER_FRAME,cycleSwfAnim);             trace("Sheet = " + pSheetArray);             swfObj.parent.removeChild(swfObj);             swfObj=null;             startAnimationPlayback();         }         //-------------------------------------------------------         //-------------------------------------------------------         //Convert fram (vector, bitmap, whatever is on the frame) into a bitmadata object         //-------------------------------------------------------         //-------------------------------------------------------         private function grabBitmap ():void {             pWidth=this.width;             pHeight=this.height;             var bmd:BitmapData=new BitmapData(pWidth,pHeight,true,0x00FFFFFF);             bmd.draw (swfObj);             var bm:Bitmap = new Bitmap();             bm.bitmapData = bmd;             pSheetArray.push (bm);         }         //-------------------------------------------------------         //-------------------------------------------------------         //Play animation         //-------------------------------------------------------         //-------------------------------------------------------         private function startAnimationPlayback():void{             this.addEventListener (Event.ENTER_FRAME,animate);             pFrame =0;         }         //         private function animate(event:Event):void{             pFrame++;             if (pFrame>pSheetArray.length){                 pFrame = 1;             }             var bm:Bitmap = pSheetArray[pFrame];             if (bm != null){                 if (this.numChildren>0){                     this.removeChildAt(0);                 }                 this.addChild(bm);             }         }     } } 
Similar articles

Open a folder in finder/explorer from a webpage?

5 years ago - Reply: 2 - Views: 80

How do I escape a reserved word in Actionscript?

5 years ago - Reply: 2 - Views: 199

Save PPS/PPT files as SWF using C#

5 years ago - Reply: 2 - Views: 171

Ways of making a graphic/visual novel in flash

6 years ago - Reply: 3 - Views: 114

Use PhoneGap + HTML5 and an Embedded Flash Movie

5 years ago - Reply: 2 - Views: 96

View word docs and PDF in browser?

5 years ago - Reply: 2 - Views: 52

ActionScript 3 Read JPEG quality

7 years ago - Reply: 2 - Views: 59

Export/Test Movie Issues

5 years ago - Reply: 3 - Views: 39

Flash always on top in Android browser workaround?

5 years ago - Reply: 2 - Views: 149

Sending Json Form from Flash AS3

5 years ago - Reply: 2 - Views: 29

parsing a swf/fla (using php?)

6 years ago - Reply: 2 - Views: 44

Getting high FPS on Flash/AIR games for mobile?

5 years ago - Reply: 2 - Views: 59

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re