views:

121

answers:

2

Hi!

I'm writing my first flash as3 game engine and there is a function call that have made me concerned over the performance.

Every frame i fill my "render bitmap" with black color using the fillRect function before i render the other sprites on it.

And then just for fun i skipped the the fillRect function just to see how much performance i would gain, and without calling fillRect my Alcon FPS counter is maxed at 112fps and when i call it i get around 90 with some text and sprites.

So my question is, is there any way to optimize or a faster way to fill the screen with a color?

Cheers!

A: 

Is there some reason you can't just put a permanent black object behind your Canvas (or whatever you're drawing on) and then do this.graphics.clear() before doing your sprite drawing?

That's what I'd suggest. Let the component with the sprites being drawn on it be transparent and just reset it every time.

thenduks
he's drawing to a bitmap so that won't work.
grapefrukt
+1  A: 

I'm pretty sure fillRect is the fastest way to reset a BitmapData object. I'm not sure how the alcon fps counter works, but fill rect should take less than a millisecond unless your bitmap is huge or your system is old.

(I'm assuming you're doing some kind of bitmap blitting which is why you need to wipe the bitmap each frame?)

Kevin