Hey everyone,
I’m playing around with a raycasting engine in haxeflixel and getting some performance issues.
I have a _canvas
flxsprite which I use to draw the whole screen. At first I was using _canvas.pixels.setPixel
but that was very slow. I moved to a cool technique of writing values to a bytearray and converting it to pixel data as outlined here http://board.flashkit.com/board/showthread.php?741099-AS3-Fast-full-screen-touch-every-pixel-updating. Way better - hit stable 60 fps.
Now I’m trying to use paletteMap() to remap it to an indexed color palette, after reading how fast this method was here: http://www.splashdust.net/2009/11/bitmapdata-and-palettemap/ and in several other places.I’m using
var rect:Rectangle = new Rectangle(0, 0, FlxG.width, FlxG.height);
_canvas.pixels.paletteMap(_canvas.pixels, rect, new Point(0, 0), null, null, null, palette);
where palette is my array of int colors.
The visual result is correct, but the performance is terrible. 10 fps, even worse than using setPixel() - can’t be right. Am I accessing the bitmapdata of _canvas in the wrong way?
Cheers
L
No, I write the color index in the alpha byte compenent of the int for convenience. Afterwards paletteMap uses that index to replace that pixel with the color in my palette array.
It's working correctly, just a tad disappointed in the performance since commenting the paletteMap operation out everything stands at 60 fps (after both ray calculations and writing values in the bytearray buffer), then when I use it it falls down at 10 fps.