Below is my code. When player (RigidBody2D
) is entering the Apple (Area2D
), only _on_Apple_body_entered
be called, eating_apple
never be called.
Apple.gd
func _on_Apple_body_entered(body):
# this function will be called
print("body entered")
Main.gd
var apple
# ...
func create_apple():
apple = preload("res://Apple.tscn").instance()
apple.connect("body_entered", self, "eating_apple")
add_child(apple)
func eating_apple():
# this function never be called
print("eating_apple")