![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | $maug |
I’ve been playing with Godot for about a week. I’m trying to expand on the Your First Game example with the squids. Here’s my goal…
- fish spawns
- player eats the fish
- fish changes to a skeleton animation and falls off the scene via gravity
So far all works great except I can’t get the signal to fire again until the dead fish falls off the screen (and is queue_free’d), like if two fish spawn at the same time only the first fish the player touches will work.
Main (Node)
--Player (Area2D)
-----AnimatedSprite
-----CollisionBody2D
--Fish (RigidBody2D)
-----AnimatedSprite
-----CollisionBody2D
-----VisibilityNotifier2D
--FishSpawner (Timer)
Here’s my code…
Main
func _on_FishSpawner_timeout() -> void:
print("new fish")
var fish = load("res://Fish.tscn").instance()
add_child(fish)
func _on_Player_eat() -> void:
print("FISH EATEN")
$Fish/AnimatedSprite.set_animation("dead")
$Fish.gravity_scale = 10
Player
signal eat
func _on_Player_body_entered(body: Node) -> void:
if body.name == "Fish":
print("Fish Touched")
emit_signal("eat")
Fish
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
So, the fish spawns every X seconds thanks to the Timer. The player touches the fish. The fish animation changes to the “dead” set and gravity is applied to make it fall off the screen. When the fish gets off the screen it frees up.
All this works fine…for a single fish. If I try to touch two+ fish with the player before the initially touched fish falls off the screen nothing happens, not even the print command.
How can my hungry squid gobble up multiple fish at once?