Page 1 of 1

[Solved] How to delete a Sprite from a SpriteBatch

Posted: Wed Jul 19, 2017 1:00 am
by SirDust
I've been studying how to use SpriteBatches from the wiki https://love2d.org/wiki/SpriteBatch

From what I see, there isn't any straightforward way to delete Sprites from a SpriteBatch, is there?
Or if not, what would be the next best way to remove them? Should I even be trying to remove them, or should I be working around that limitation?

Re: How to delete a Sprite from a SpriteBatch

Posted: Wed Jul 19, 2017 2:19 am
by zorg
You can either remove and re-add all sprites into the batch, skipping the ones you want to "delete", or you can set the ones slated for deletion to the degenerate case of having scale factors 0,0; which won't draw the sprite at all, though it will still take up one index.

Re: How to delete a Sprite from a SpriteBatch

Posted: Wed Jul 19, 2017 9:13 am
by Luke100000
from https://love2d.org/wiki/SpriteBatch:set
SpriteBatches do not support removing individual sprites. One can do a pseudo removal (instead of clearing and re-adding everything) by:

Code: Select all

SpriteBatch:set(id, 0, 0, 0, 0, 0)
This makes all the sprite's vertices equal (because the x and y scales are 0), which prevents the GPU from fully processing the sprite when drawing the SpriteBatch.
So, as Zorg said, refill the entire spritebatch if you want to remove a lot of sprites or set this one sprite to 0,0. You can reuse this sprite using spritebatch:set later instead of adding another sprite.

Re: [Solved] How to delete a Sprite from a SpriteBatch

Posted: Sat Aug 18, 2018 6:33 pm
by rmcode
Necro-ing this thread because my question is directly related:

I assume when you "just" pseudo-delete the sprites, it would take a lot of "deleted" sprites before it had any notable impact on the GPU?