0
votes

I have a project where i'm drawing to a stageSized bitmap by using BitmapData.draw

using the 'show update regions' feature of the debug player, i can see that the player always updates the whole stage although i changed only a small part of the bitmapdata.

Can I somehow make the player only update that part of the screen where there were changes made to the bitmap data?

2
You have to split it for few bitmaps . Its normal that if You using draw function it paint again whole object .turbosqel
I'm doing this right now and it is a lot faster - however, i get very strange graphic glitches which i cannot explain. while painting, only small portions of the bitmaps get actually drawn to screen. if i paint over the same area a bit later, i can see that the strokes were added to the bitmap data correctly before, but not all of it got shown on screen.Mat
okay - now it's working. if i lock the bitmapdatas before using draw on them and afterwards call unlock, then i don't get those strange glitches. now it's fast =)Mat
cool , good to hear You fix problem .turbosqel

2 Answers

0
votes

Would it be possible to use copyPixels instead? It only allows copying from another BitmapData, but most of the time that should be fine (you could always cache animations to bitmapdata once, and then use the cached data instead of the Draw-method). Flash player should be able to redraw only the altered parts when you use copyPixels.

However, the real question; is this really an issue? Don't optimize these things unless you actually need to :)

0
votes

If you're only redrawing part of the bitmap, then only that part should get updated by Flash Player.

You can see it in action here:

public class Test extends Sprite
{
    public function Test()
    {
        stage.align = "topLeft";
        stage.scaleMode = "noScale";

        var bitmap:Bitmap = new Bitmap();
        addChild(bitmap);

        var bd:BitmapData = new BitmapData(400, 400);
        bitmap.bitmapData = bd;

        // One-second timer.
        var timer:Timer = new Timer(1000);
        timer.start();
        timer.addEventListener("timer", timerHandler);
    }

    private function timerHandler(event:Event):void
    {
        var bitmap:Bitmap = Bitmap(getChildAt(0));
        var bd:BitmapData = bitmap.bitmapData;

        // Draw 100x100 square in random location, with random color.    
        var xPos:Number = Math.random() * 300;
        var yPos:Number = Math.random() * 300;

        var matrix:Matrix = new Matrix(1, 0, 0, 1, xPos, yPos);

        var color:uint = Math.round(Math.random() * 0xFFFFFF) | 0xFF000000;

        var colorTransform:ColorTransform = new ColorTransform();
        colorTransform.color = color;

        var shape:Shape = new Shape();

        var g:Graphics = shape.graphics;

        g.beginFill(0xFFFFFF);
        g.drawRect(0, 0, 100, 100);
        g.endFill();

        bd.draw(shape, matrix, colorTransform);
    }
}

Try this with "Show Redraw Regions" in the standalone Flash Player, and you'll see it updates only the newly drawn part on each tick.