## [Solved] How to delete a Sprite from a SpriteBatch

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

### [Solved] How to delete a Sprite from a SpriteBatch

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?
Last edited by SirDust on Fri Aug 11, 2017 12:27 am, edited 1 time in total.

zorg
Party member
Posts: 2937
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: 231
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
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.

rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

### 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?

### Who is online

Users browsing this forum: Bing [Bot] and 15 guests