0 votes
    extends Area2D

    var position_draw = Vector2(200, 100)
    var _can_click = false

    func _ready():

        var a = Sprite.new()
        a.name = "test_sprite"
        a.texture = load("res://img/120px-Roundel_of_El_Salvador.svg.png")
        a.position = position_draw
        self.add_child(a, true)

        var coll = CollisionShape2D.new()
        coll.name = "test_collision"
        var circle = CircleShape2D.new()
        circle.radius = 200
        coll.shape = circle
        coll.position = position_draw
        self.add_child_below_node($test_sprite, coll, true)

        #    ┠╴test_sprite
        #    ┖╴test_collision

        self.connect("mouse_entered", self, "_on_Area2D_mouse_entered") 
        self.connect("mouse_exited", self, "_on_Area_2D_mouse_exited") 

    func _on_Area2D_mouse_entered():
            _can_click = true #Not work

    func _on_Area2D_mouse_exited():
            _can_click = false #Not work

    func _click_check():
           if _can_click:
                if Input.is_action_pressed("click"):
                      print('Click') #Not work

    func _process(_delta):
Godot version 3.5.1
in Engine by (17 points)

1 Answer

0 votes
Best answer

The above code works fine for me except that you have a typo in your signal name here:

self.connect("mouse_exited", self, "_on_Area_2D_mouse_exited

That should be _on_Area2D_mouse_exitedto match your function name.

by (19,292 points)
selected by

Thank you, you helped me understand the problem.
Tell me why everything works like this:


That's how the script Area2D breaks:

    ┠╴ColorRect   #Background

How can I fix this so that I can add other nodes and the script Area2D doesn't break?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.