flixel
flixel copied to clipboard
Proposal: `FlxSprite` `lockFramePixels:Bool` to prevent redraws
While looking into the performance of the pixelPerfectCheck html5 demo, I noticed part of the perf issues were from pixelPerfectCheck calling drawFrame on both sprites. This means when checking a sprite's pixels against 50 other sprites, the exact same framePixels were rendered 50 times (on renderTile targets, if they are somewhat close to each other).
I propose mySprite.lockFramePixels to allow devs to prevent internal redraws. updateFramePixels will check it and if it's true it returns whatever the current framePixels is, instead of drawing a new one.
Pros:
- Easy to implement, 2 lines + documentation
- No changes to existing flixel projects, no effect to anyone not using the property
- Provides easy control over otherwise under-the-hood processes, for performance gains
Cons:
- Parity issues when true. on
renderBlittargets the sprite is completely static, where onrenderTileit appears to have no effect on the actualdraw()phase, becauseframePixelsisn't actually used for that. Not sure how well known this is to flixel devs - Potentially confusing (see above), can be used erroneously or abused. The documentation will need to be extremely clear.
- Projects can already easily implement this by extending FlxSprite