Hi all,
Comments on overheads (memory/performance) on the following techniques?
These are overly simplified, but you get the idea?
Bitmap.visible
// Assume we have a bunch of sprites already in memory as bitmap data
var spriteData : Vector.<BitmapData>;
// Now we create a sprite for each 'frame' of animation
var bitmaps : Vector.<Bitmap> = new Vector.<Bitmap>();
var bitmap : Bitmap;
for (var i:int=0; i<spriteData.length; i++){
bitmap = new Bitmap( spriteData[i] );
addChild(bitmap);
bitmaps.push(bitmap);
bitmap.visible = false;
}
// Now when we animate we simply set bitmaps visiblity
public function gotoAndStop( frame : int ):void{
bitmaps[ currentFrame ].visible = false;
currentFrame = frame;
bitmaps[ currentFrame ].visible = true;
}
BitmapData replacement
// Assume we have a bunch of sprites already in memory as bitmap data
var spriteData : Vector.<BitmapData>;
// Now we create a single sprite
var bitmap : Bitmap;
addChild(bitmap);
// Now when we animate we swap bitmap data
public function gotoAndStop( frame : int ):void{
bitmap.bitmapData = spriteData[ frame ];
}
I haven't performed this test on mobile yet - just wanted to get thoughts first. Obviously if the animation has a lot of frames then the top one has a huge overhead, but is there a performance hit to swapping the bitmapData of a bitmap?
Cheers,
Peter
North America
Europe, Middle East and Africa
Asia Pacific