Hello, I need help with Label and hover mouse

Godot Version

Godot version 4.2.1

Question

Hi there. Thanks for visiting my post. =)
I’m trying to do this: when hover Button, the number of Label will go from 100 to 0 smoothly.
I used Button & Label, and the tree look like this:

game {Node2D}
+ Button # signal mouse_entered to Label
+ Label # added script

Then I tried this code:

var score = 100

func scoreUpdate():
	$Label.text = str(score)

func _on_Label_mouse_entered():
	score = score - 1
	scoreUpdate()

But nothing happen when hover button. =(

So, here are my questions:

  • How to fix my code ?
    Or if there is a better way, I would love to listen from you.

  • Is it possible to change property by this way ? (like: make sprite2D fade slowly)
    Some examples would be nice.

Thank you very much for your time. =)
And thanks Godot’s community too.

So hovering the button should change the score, but your function is called on_Label_mouse_entered. Are you sure you’re connected the button’s signal?

edit:
But the signal will only be sent once so it’ll only change your score to 99. You could do something like this:

You can set target score to any number and score will be “smoothly” set to target_score

1 Like

Hug you with love and gratitude =D
And you are right, it should be _on_Button_mouse_entered()
It works like magic, plus I learned about _process(delta) & move_towards(), thanks to you.
Hope that you will come and fix me more in future.
See you again =)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.