Deleting only specific objects/sprites


#1

So I am making a game in which a character can cut down a tree stump.

The tree stump is one single object in the objects list.
I want the tree stump object that the character is in collision with to be deleted.
It all works fine until i decide that i want to have more than one tree stump.
If my character now collides with one of the tree stumps it deletes both because i told it to delete the object.

So is there any way of telling the game, to only delete the stump that the character is in collision with, so that it doesn’t delete both.

My solution for now was to just make them two separate objects.
The problem with that is that i have to make a new variable and copy all the events for every new stump object i want to make. That seems much to complicated…

Thanks to anyone who might have a solution to this!


#2

For this, you need a For Each event.
You can know more about For Each here: http://wiki.compilgames.net/doku.php/gdevelop5/events/foreach

See the example below. The object called Platform has multiple instances. The instance which collides with the Player gets deleted, the others stay unaffected.


#3

Wow!
Thank you so much that was exactly what i needed!


#4

I’m happy to help :smiley:


#5

Hi! I am also having a problem. If I create a scene variable “enemylife” is set to 50 and if “bullet” is collide with “enemy” it subtracts to 1. If the player hits the enemy for 50th time. I want to delete the enemy. But I have a set spawn timer for enemy if the enemy was deleted it won’t spawn anymore. can you please help me?


#6

Hey there,

If I understood your question correctly, your problems is that you are not “reseting” your Enemylife variable. In this case the second enemy is created with an Enemylife = 0.
In the last condition, set the scene variable “Enemylife” back to 50 after deleting the enemy.
That should do it!

-Ben