0 votes

Hi all. So very close to getting a game functioning the way I envisioned. Little problem, though...

I spawn in my enemies at one side of the screen, and they move to the opposite side. That part works. The first enemy that reaches the Player's base is freed from the queue, and stops the enemies from spawning. That also works. But how do I apply queue_free() to the remaining enemies?

in Engine by (197 points)
edited by

I think my Level.gd script would be necessary. This section is from the part that initiates "Game Over"

func _on_BaseArea_area_entered(area):
    print("Collision!")
    $Node/SpawnTimer.stop()
    $Node/SurvivalTimer.stop()
    $HUD.player_loss() 
    emit_signal('game_over')
    $BaseArea/CollisionShape2D.disabled = true
    get_tree().call_group("EyeWorms", "queue_free") # This is the new
# line.

1 Answer

0 votes
Best answer

You can add the enemy scene itself to a user-defined group. Call the group anything you want; like enemies. Any instances of the scene will be included in this group. Then all you need to do to free them all at once is-

get_tree.call_group("enemies", "queue_free")
by (3,871 points)
selected by

After a little poking around, I put

get_tree().call_group("EyeWorms", "queue_free")

into the code block. Doesn't do anything as far as I can see.

Did I not do something right?

Did you add the enemy scene to a group called EyeWorms? Just so you know, the naming is case-sensitive.

Ah, silly me. I wrote "enemies" instead of "EyeWorms". The enemies were in the group, I just forgot to actually call said group. Thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.