Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Quartez |
Hi, it’s my first time asking question at here, forgive me if I done anything wrong XD.
I’ve added a child(tooltip) to my scene and change its position everytime my mouse move within the TextureButton.
func _process(delta):
if follow:
if previous_mouse == null:
previous_mouse = get_global_mouse_position()
else:
if previous_mouse != get_global_mouse_position():
get_tree().get_root().get_node("Tooltip").set_position(get_global_mouse_position())
func _on_TextureButton_mouse_entered():
var tooltip_instance = tooltip.instance()
get_tree().get_root().add_child(tooltip_instance)
follow = true
func _on_TextureButton_mouse_exited():
get_tree().get_root().get_node("Tooltip").queue_free()
previous_mouse = null
follow = false
It works if I move my mouse up and left, but when moving down and right, the placement of the tooltip seem out of place. Could anyone helps me figure it out what is happening?
The problem:
Imgur: The magic of the Internet
Thanks in advance!
It’s stange, I’ve not tested these options but you may try:
a) Change the logic to only call the function when a mouse motion event triggers:
func _input(event):
if event is InputEventMouseMotion:
#Do logic here
b) Try to interpolate between the current position and the new position, it may not correct it completely but will help with the jitter.
davidoc | 2021-07-19 21:13