Out of curiosity, is there a faster way to draw on BitmapData objects, than setPixel?

I’m using haxeflixel to do some text-mode rendering. I already had some success with using haxeflixel tilemaps but someone suggested I oughtta do it the old fashioned way and literally render it pixel by pixel. Since BitmapData is an openfl class, I thought I’d ask here. Even locking/unlocking doesn’t seem to help the speed any.so any suggestions on using something other than SetPixel – maybe go even further down to lime or something?

Under the OpenFL BitmapData class, there is a Lime Image instance. Each Image has an ImageBuffer, which may use data (for UInt8Array-based pixel data), or a src value of a CanvasElement or ImageElement on HTML5.

There are some different formats used, such as BGRA or premultiplied alpha. When you use getPixels the data needs to be converted into unpremultiplied ARGB pixels for the Flash API, then converted back when you setPixels. If you render directly this is not necessarily the case, but you have to be more aware of the image format.

Another option might be using the shape.graphics API, to render that way. That also renders to a bitmap, currently.

Manipulation of individual pixels is an area where native code outperforms Haxe compiled code – that’s also an option for true “fastest manipulation”

I’m still wanting to keep it in haxe. I don’t want to resort to having to go native on each platform. That just means writing several programs instead of one. The actual SetPixels (plural) function I believe takes a byte array, maybe I could just work on byte data directly and then use setpixels to copy it to the bitmapdata object?

Yeah, it’s worth a try if you are modifying many pixels at once. The other thing you can do is try to consider if you can limit how often you change the pixel values, caching BitmapData for possible images you may need, etc

Setpixels and bytearrays seem a bit slower than just using setpixel directly.

Also am thinking about messing with this so I can learn old school demo effects (starfields, plasma, fire, zoom, rotozoom, etc) – I may do it any way, just being aware that it’s generally slow. (Of course when I compile for release mode, it’s not quite as slow as debug, and may be good enough).

Also with the demo stuff, I may decide to do a low res like 320x240 — which is half the res I’m doing my text mode stuff in.

I haven’t decided whether I’m going to go full ahead with a character renderer.

I’m leaning toward just going back to haxeflixel tilemaps (I still have the program and everything)