开发者

Godot 4.0.b7: Attach mouse-entered signal via code to dynamically generated CollisionShape2D

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜