Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a check if mouse is in control method #3956

Open
dryluggage opened this issue Feb 12, 2022 · 4 comments
Open

add a check if mouse is in control method #3956

dryluggage opened this issue Feb 12, 2022 · 4 comments

Comments

@dryluggage
Copy link

Describe the project you are working on

slay the spire like card game

Describe the problem or limitation you are having in your project

when moving a control node and the mouse is stationary and the control moves under the mouse it doesnt send mouse_entered/exited signals

this also is the case with area2d nodes

Describe the feature / enhancement and how it helps to overcome the problem or limitation

a function that checks if the mouse is inside the control then i can just call this function manualy after the control move is over

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

a is_mouse_inside function inside the control node maybe ? or a better name

If this enhancement will not be used often, can it be worked around with a few lines of script?

you would need to get the controlrect ,transorm and the mouseposition and find a way to manually check the collision

Is there a reason why this should be core and not an add-on in the asset library?

since the control has a the mouse_exited/entered signals i think that such a function would already exist in the control node but isnt exposed yet

@zinnschlag
Copy link

Related to godotengine/godot#40012 ?

@raulsntos
Copy link
Member

raulsntos commented Feb 12, 2022

you would need to get the controlrect ,transorm and the mouseposition and find a way to manually check the collision

var rect = control.get_global_rect()
var mouse_position = control.get_global_mouse_position()
if rect.has_point(mouse_position):
	print("mouse is inside control")
else:
	print("mouse is NOT inside control")

@deakcor
Copy link

deakcor commented Sep 17, 2022

you would need to get the controlrect ,transorm and the mouseposition and find a way to manually check the collision

var rect = control.get_global_rect()
var mouse_position = control.get_global_mouse_position()
if rect.has_point(mouse_position):
	print("mouse is inside control")
else:
	print("mouse is NOT inside control")

This work in a lot of case but can be not enough because a position can be in the control but blocked by another control.

@Sauermann
Copy link

Sauermann commented Jun 29, 2023

For Area2D-nodes this has been solved in godotengine/godot#78017.
Now you can listen for mouse_entered and mouse_exited signals in order to determine, if the mouse is over the node, even if it was causes by moving the node, while the mouse stands still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants