PDA

View Full Version : Slow performance with Bitmap erasing


rpersso
11-26-2008, 12:14 AM
Hello, for the past couple of weeks I've been learning AS3, and for a school project I'm doing a remake of the popular DOS game Liero. Everything is working fine, I got a layer of dirt that I am shooting away, but the problem is that after a few hundred bullets, the game starts to lag heavily whenever a shot is fired.

I'm using a simple bitmap and a brush to erase the parts where the bullets hit.

// Drawing stage
bmap = new BitmapData(1100,800, true, 0);
dispBmp = new Bitmap(bmap);
addChild(dispBmp);
brush = new Shape();
erase = new Shape();

brush.graphics.beginFill(0xBA7001);
brush.graphics.drawRect(0,0,1100,800 - 183);
brush.graphics.endFill();
bmap.draw(brush, null, null, "normal");

// Erasing place where bullet hits, I repeat this for all pixels surrounding the area in a certain radius
erase.graphics.drawRect(Math.round(bullets[i].x), Math.round(bullets[i].y), 1, 1);

Any thoughts? Am I going about this all wrong? I've been searching the internet for days trying to find some legible information on this, but I'm about to give up. Any help would be greatly appreciated!

geekdenz
02-11-2009, 01:58 AM
Is this code inside a function? If yes, make sure the bitmap is not added multiple times. Also maybe look at not making new objects each time if u can avoid it.