Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | beeftendon |
This is more of a design principles question based on the “Your First Game”/“Dodge the Creeps” tutorial from the official docs: https://docs.godotengine.org/en/stable/getting_started/step_by_step/your_first_game.html
The tutorial instructs us to call get_tree().call_group('mobs', 'queue_free')
in Main.game_over
, which causes the mobs to disappear as soon as the player gets hit. However, I thought it’d be nice to have the mobs continue to exist until the title screen reappears. I’ve done this by simply moving the same queue_free
call to HUD.show_game_over
after the timer, as shown below:
func show_game_over():
show_message("Game Over")
# Wait until the MessageTimer has counted down.
yield($MessageTimer, 'timeout')
get_tree().call_group('mobs', 'queue_free') # Moved from Main.gd
$Message.text = 'Dodge the\nCreeps!'
$Message.show()
# Make a one-shot timer and wait for it to finish.
yield(self.get_tree().create_timer(1), 'timeout')
$StartButton.show()
This accomplishes what I want, and it does seem that one of the uses of call_group
is its ability to communicate between scenes. However, it feels intuitively wrong to have the HUD
scene responsible for removing non-HUD objects. Is my concern here valid, or is this a valid design practice in Godot?