0 votes

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

asked May 7 in Engine by start123 (43 points)

1 Answer

+1 vote
Best answer

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.

answered May 7 by njamster (8,986 points)
selected May 19 by start123

How to make a label attached to a mouse?

Attach the following script to your Label:

extends Label

func _process(_delta):
    rect_position = get_global_mouse_position()

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

I just did on your other question over here.

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.