How to show a label when mouse hover over an sprite?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By start123

I want to make an inventory for a character. When the mouse hovering over a slot with an item, its description must be shown.

:bust_in_silhouette: Reply From: njamster

You can use a TextureRect instead of a Sprite and connect it’s mouse_entered- and mouse_exited-signals to show or hide the label respectively:

extends TextureRect

func ready():
    connect("mouse_entered", self, "_on_mouse_entered")
    connect("mouse_exited", self, "_on_mouse_exited")

func _on_mouse_entered():
    $Label.show()

func _on_mouse_exited():
    $Label.hide()

The script above assumes that your label-node is a direct child of the TextureRect, if that’s not the case you need to adapt the path to the label-node accordingly.

How to make a label attached to a mouse?

start123 | 2020-05-11 13:58

Attach the following script to your Label:

extends Label

func _process(_delta):
	rect_position = get_global_mouse_position()

njamster | 2020-05-11 14:04

can you answer is there a command that changes the text on the label?

start123 | 2020-05-11 14:17

I just did on your other question over here.

njamster | 2020-05-11 14:23