0 votes

I wan't to use an Area2D on the UI of my game but i don't now how to interact with something on the canvas layer

in Engine by (36 points)

What do you mean by "interact"? Do you have trouble getting the node? If so, how does your scene tree look like and which node holds the script in which you're trying to get the node?

Quick example:

if i make a custom mouse with a sprite on and then hover it
over an Area2D(with body enterred signal)connected
to the canvaslayer. The Area2D will actually not detect it

Basicly the area 2D node does not work

if i make a custom mouse with a sprite on

Ambiguous! Do you mean you added a Sprite-node to the scene and let it follow the mouse cursor? Or are you talking about actually changing the mouse cursor?

hover it over an Area2D(with body enterred signal)connected to the canvaslayer.

You keep mentioning the term "CanvasLayer". Are you talking about the default CanvasLayer which forms the root-node of the scene-tree or have you actually added additional ones to the tree? Also: How is that relevant here?

The Area2D will actually not detect it

Why should it? A Sprite-node is not a body, thus no body is entering the area. The body_entered-signal will only trigger on a Kinematic-, Static- or RigidBody.

I still don't get what's your problem and where you need help...

you just helped me without helping me

the reason it did not work is because i used a sprite and body entered does not detect that. You just reminded me and now i know i have to change it to a different kind of node or another sort of code

Also i come from game maker where you usally have problems detecting the mouse on a UI layer.
thats the only reason i actually tried to attach a sprite to the mouse cursor as a workaround.

So if you still want to help me then how do i detect a mouse with an Area2D whitout attaching something to it because if i dont mistake the cursor is not a body

2 Answers

0 votes

Quick example:

if i make a custom mouse with a sprite on and then hover it
over an Area2D(with body enterred signal)connected
to the canvaslayer. The Area2D will actually not detect it

by (36 points)
0 votes

how do i detect a mouse with an Area2D

Connect its mouse_entered- and mouse_exited-signals:

func _on_Area2D_mouse_entered():
    print("Mouse entered the Area2D")

func _on_Area2D_mouse_exited():
    print("Mouse exited the Area2D")

Note that Control-nodes provide those signals as well, so for UI you don't have to use an Area2D (which requires a CollisionShape2D to function properly).

by (10,225 points)
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 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 webmaster@godotengine.org with your username.