flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Proposal: `FlxSprite` `lockFramePixels:Bool` to prevent redraws

Open Geokureli opened this issue 4 years ago • 0 comments

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 renderBlit targets the sprite is completely static, where on renderTile it appears to have no effect on the actual draw() phase, because framePixels isn'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

Geokureli avatar Sep 16 '21 15:09 Geokureli