I’m making a 2D simple game similar to the “Space Invader”.
I want to create an area to display the number of enemies:
When the bullet destroy an enemy, a samll square on the right is also deleted at the same time.
But I can not find the way to do this
I created the squares by repeatly create each object on each row
When I use the command: delete if collision, but this will delete all the blood objects when collison
If anyone has an ideal or code to resolve this matter, please help me.
Thank you so much !
The easier (but not the best) way to delete these square is by using instance variable (we’ll call it “countID”) for the squares, and then have global variable to keep track of how many enemies killed.
One event will be like this:
When enemy is destroyed | Add 1 to killcount global variable
And then another event will be:
If global variable killcount > countID variable of square | Delete square
If we set up instance variable with different value, for example: the first square’s countID variable is 1, it will be deleted when we kill one enemy.
For another square, we can set the countID variable to 2, and it will only be deleted if killcount is 2.
An example is me putting different enemy health for my game (same enemy object):
and enemy B
If I attack them both same time with AOE attack, enemy B will die first since it has less health.
Instance variable is the same as object variable, except that we can assign to a specific… instance, to say the least, of the object.
Here’s the documentation if you want more explaination:
By the way, the Instance Variable is at bottom left of Object Properties, you will need to scroll down a bit (bottom left).
Next step, we can make it more automated using loop to generate and assign instance variable to each square, but I won’t go over the detail of that in this post. But it will save time, and be useful when you want to add more enemy than usual especially!
I’d thought about the method “countID” already,
I can create all squares by using loop (add row, add column…etc) and assign ID for each square ( by using variable)
but the problem is: when we delete, Gdevelop have only one command: delete object. This command does not refer any date except name of object.
There for, in case I assign each square with an ID (by variable) , I still can not delete exactly an object by refering its ID.
That’s great that you’ve tried it!
Yes, there’s only Delete Object command, with name. You can refer to the square ID by making it the condition of the event when an enemy is killed. Something like:
Enemy is killed | Delete Enemy
Then, create a sub event.
countID of square is == enemyKilled | Delete square
The sub-event, with the condition, should solve it. Basically, the condition is selecting only the square with the ID at the same time the enemy is deleted.
If that does not solve it, you can experiment with a For Each event, with the same conditions maybe?
Hi Cat ! Thank you so much !
I also tried the even “For Each” and its still does not work, because square is objected at “action”, not at “condition”. The countID also does not run or I programmed wrong code.
If the “delete command” can identify exactly position or ID of an specific, we can resolve this matter. So I thought this is limit of Gdevelop.
Today, I come up with a new ideal to do, I create a new object (same size with square) at position coincide with square. So I have a “mask” in front of the square ( by change Z-Order)