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?
[Solved] How to delete a Sprite from a SpriteBatch
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved] How to delete a Sprite from a SpriteBatch
Last edited by SirDust on Fri Aug 11, 2017 12:27 am, edited 1 time in total.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to delete a Sprite from a SpriteBatch
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.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
- Luke100000
- Party member
- Posts: 232
- Joined: Mon Jul 22, 2013 9:17 am
- Location: Austria
- Contact:
Re: How to delete a Sprite from a SpriteBatch
from https://love2d.org/wiki/SpriteBatch:set
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.SpriteBatches do not support removing individual sprites. One can do a pseudo removal (instead of clearing and re-adding everything) by:
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.Code: Select all
SpriteBatch:set(id, 0, 0, 0, 0, 0)
Re: [Solved] How to delete a Sprite from a SpriteBatch
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?
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?
Who is online
Users browsing this forum: Bing [Bot] and 4 guests