So I started a project that has physics and lots of small particles, most were movieclips so needless to say, the framerate became a issue. Now I’m trying to learn how to render the stage with bitmapData but it it’s a bit complicated. Here’s what I have now, and it works, but I’m not 100% comfortable with how this all works or even if I’m going about it the right way.
public class Main extends Sprite {
public var Objects:Array = new Array();
public var RenderBuffer:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true,0x00000);
public var hero:Hero = new Hero();
public function Main(){
addEventListener(Event.ENTER_FRAME, Loop);
addChild(new Bitmap(RenderBuffer));
Objects.push(hero);
}
public function Loop(e:Event):void{
for (var i:uint = 0 ; i < Objects.length ; i++){
//Update
Objects*.x += Objects*.velocity.x;
Objects*.y += Objects*.velocity.y;
//Render
var tempBuffer:BitmapData = new BitmapData(Objects*.width,Objects*.height,true)
tempBuffer.draw(Objects*);
RenderBuffer.fillRect(RenderBuffer.rect,0x000000);
RenderBuffer.copyPixels(tempBuffer,tempBuffer.rect,new Point(Objects*.x,Objects*.y));
}
}
*the Hero class is a graphic in my library
So basically what im doing is cycling through all my current active objects, creating a temp bitmapdata object to render the graphic, then copying that temp bitmapData onto my main renderer and positioning it correctly.
Seems a bit tideous, but am I going about this the right way? Also, how does creating animating graphics work?