views:

429

answers:

2

I posted this to the Adobe forums but I don't expect a good answer there. I am looking for help from someone who has done a game in flash and has encountered the same problem.

Steps to reproduce my problem:

  1. Create simple dot DisplayObject in flash

    dot.graphics.beginFill( color);
    dot.graphics.drawCircle( 0, 0, 2 );
    dot.graphics.endFill();
    
  2. Draw dot to bitmap many times a frame

    bitmapData.draw( dot, null, null, "normal", null, _smoothing );
    
  3. Test FrameRate in combination of browsers,flash plugin versions on Win32

Expect:

Framerate to be close in most cases

Observed:

I am seeing a 25% decrease in framerate under IE7 using Flash10b.ocx(10.0.22) and 50% decrease in framerate using Flash10c.ocx(10.0.32). PLugins under FireFox, Safari and in Mac OSX don't exhibit the same slowdown.

Help please:

I would like to get help/confirmation on a performance problem that I see in Internet Explorer. The Adobe and Flash community is great on the Internet but I have been surprised to see no information on this, just a few reports about movie playback on 10.0.32 vs. 10.0.22.

My guess is that in IE flash plugin is passing draw calls to Win32 and that this is slow.

My solution is:

Instead of drawing each time on the bitmap using draw, cache the draw calls to a bitmap and use CopyPixels. When I do this the performance is the same across browsers, within 10%.

bitmapData.copyPixels(dot.bitmapData,dot.bitmapData.rect,new Point(dot.x,dot.y),null,null,true);

Loop I am using:

function enterFrame(e:Event) {
    bitmap.lock();

    for (var i:int=0;i<particles.length;i++) {
        draw(particle[i]);
    }

    bitmap.unlock();
}

Notes about other possibly "known" issues I would like to know more about:

  • Under IE the memory use for my application is reported to be much smaller (33MB typically in flashplayer, 16MB under IE).
  • Under IE the memory page faults are at over 10k/sec whereas in the flash player there are none.
  • Under IE the stage.invalidate seems to cause performance hitching problems.
  • Under IE the putting a blur filter on the bitmap has bigger performance hit that in the flash player.
A: 

Flash plugin performance (wildly) differently across every platform/browser/minor version/debugger/etc. There is little you can do to offset these differences besides coding for the least common denominator of your target audience.

That said, bitmapData.draw is slow, as it forces re-rasterization of the vector data on every call. Under the hood, Flash uses this method too, but it keeps track of dirty regions of the screen so it calls it less than you do (turn on "show redraw regions" in the debugger to see this visually).

Your bitmapData.copyPixels solution is the correct one for manual raster implementations. This is pretty much the only mechanism to get high-performance complex animation in Flash.

Cory Petosky
A: 

Thanks for the confirmation. I thought the purpose of the lock is to help flash minimize redraws. I see the stuttering even though flash app is running at close to 60 fps.

Rather than people wondering if I coded everything right. I modified some brand new tweenlite performance example code to be linear movement of around 150 pixels /sec. This highlights the stuttering for people to see. Example is at http://forums.greensock.com/viewtopic.php?f=1&amp;t=1857.

memorywar
Ah, that's the famous Flash "shearing" bug that's been in the player since it first came about. There's no solution or workaround.
Cory Petosky