I need to render about 100 objects (or tiles), 32px wide squares. Each object has its own custom texture of same size which changes over time (let’s say up to 5 times a second, usually lot less) and there is no way to pre-render this texture as it is dynamically generated. Additionally, each object can change it’s position and alpha. I need it running on native targets.
What would be the best approach to render this? Usual approaches seem to deal with only drawing pre-rendered assets. Right now I have a set of Bitmaps and I’m changing their BitmapData, but this seem to crash more often than not. Also, if I’m creating new Bitmap object each time texture regenerates, I also get a lot of crashes, GC doesn’t seem to be able to deal with so many objects or something like that.
Well, not exactly. My textures are “pixel art”, they are made by manipulating individual pixels, so rendering to texture probably won’t help me, at least I don’t see how. These textures are fairly small, so there should be no problem uploading them to GPU every time they are regenerated.
The problem is that with all rendering methods I tried I’ve got crashes. Changing bitmapData of Bitmap on display list crashes. Removing bitmap, then creating new one with texture and adding it back also crashes. Only thing that works is using Graphics.beginBitmapFill() on Shape (not ideal, since Graphics should be used for vector art), but this gives me blurry result when upscaled (as it is pixel art), it ignores the smooth settings since renderer was reworked in 4.0, it worked fine in 3.x (https://github.com/openfl/openfl/issues/1222).
Does it work if you leave
Bitmap, and modify the source
Thank you very much for a tip, it seems you just saved me hours of trial and error. Currently I’m pre-rendering texture to the BitmapData object in worker thread and then using copyPixels() to copy it to the Bitmap.bitmapData (which is on stage) while in ENTER_FRAME event handler method. At the moment this seems stable. Changing Bitmap.bitmapData to other BitmapData object crashes the application with no error message, but I’m not sure if this is good practice anyway.