I have an array of dynamically generated 'planets' tha开发者_JAVA百科t need to be able to interact with the mouse. I have been trying to use the new Godot 4 signals format, but no joy yet.
The following code works correctly:
func _ready():
for planet in planets:
var planet_collision_shape = CollisionShape2D.new()
planet_collision_shape.shape = CircleShape2D.new()
planet_collision_shape.shape.radius = 27.5
planet_collision_shape.position = Vector2(planet._coord[0], planet._coord[1])
add_child(planet_collision_shape)
planet._body = planet_collision_shape
But attempts to implement a signal with the following code generates an error code of:
Invalid get index 'mouse_entered' (on base: 'CircleShape2D').
planet._body.shape.mouse_entered.connect(self._on_mouse_entered)
The node tree is nested as follows, with the dynamically generated nodes attaching to the Camera2D.
Node2D -> CanvasLayer -> Camera2D
精彩评论