Child instance incorrectly placed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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

:bust_in_silhouette: Reply From: Mison

Have you tried replacing the image with another which doesn’t have any transparency. It looks the the transparent pixels in the Godot icon is tripping it up.

Thank you for the answer! I’ve tried it, but it still has the same problem

Quartez | 2021-07-20 11:35

:bust_in_silhouette: Reply From: Quartez

Thanks for the responses guys, much appreciate!
I’m not 100% sure about that, but I suspect that it’s because whenever my mouse hover to the right/down side, the cursor enters the tooltip. Seem like Godot considers it as my cursor already left the TextureButton and removes the tooltip.

I added offset for the toolip position and it seem like the problem is solved.

Solution:

Well done - glad you got there!

Mison | 2021-07-20 16:58