Copying pixels from FP.Buffer


(Ricesteam) #1

I can’t seem to get .copypixels working. For example in an Entity:

override public function render():void {
    //super.render()
    var containerData:BitmapData = new BitmapData(550, 400, false, 0xFFFFFFFF);
    containerData.copyPixels(FP.buffer, FP.buffer.rect, new Point(x, y));
    graphic.render(containerData, new Point(x, y), new Point(FP.camera.x, FP.camera.y));
}

or

var containerData:BitmapData = FP.buffer.clone();
graphic.render(containerData, new Point(x, y), new Point(FP.camera.x, FP.camera.y));

Nothing is being rendered.

Essentially, I’m trying to create a “trail” effect for the player motion by copying the sprite and drawing the copies. Not sure if there’s a better way? I’m using Spritemap for the player sprite.


(azrafe7) #2

It seems that you’re rendering the Entity’s graphic to containerData (a copy of FP.buffer), but then you’re not drawing it back to FP.buffer.

You should also consider promoting containerData to class member, so that you won’t need to instantiate a new one in each render step. And make your BitmapData transparent so that will blend with the screen (or use BlendMode.ADD).

There are many approaches to create a trail effect and you’re on the right track.

Maybe the simplest one is to just use a Graphiclist, store multiple copies of the same sprite in it and draw them at different distances from the main one (with different alpha values).

For nice blurred trails you can take a look at Reiss’ code.

Shameless plug: ooor… use punk.fx to do it (demo | demo source | lib repo).