[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.
Post Reply
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

[Solved] How to delete a Sprite from a SpriteBatch

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

Post 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.
Me and my stuff :3True 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.
User avatar
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

Post 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.
User avatar
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

Post 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?
Post Reply

Who is online

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