Menu icons on hover

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I have a simple menu with some button nodes in my game. I want to make it so when the button is selected/hovered, two arrow icons will appear at the ends of the text of the button. How can I achieve that?

1 Like

All canvas items have methods called show() and hide() that do what their names imply. So you can call show() on the arrow icons to make them appear, and hide() to make them disappear again.

When the mouse enters and exits any control node, such as your button, the button will emit a signal - either mouse_entered or mouse_exited. You can use those signals to detect when you should show or hide the arrow icons.

Relevant documentation:

2 Likes

i like to use set_visible(true) and set_visible(false) better.
if you want to use this or show() and hide() is based on the preferences of you and your team

1 Like

Would it be better to create a custom scene of a button that has these arrows? I want pretty much every menu button in my game to have them

1 Like

Is this the effect you’re trying to achieve? If so, I’d just make it as part of the theme. That way you don’t have to manually hide / show it, worry about signals etc. The downside is that this can’t be animated… but it’s simple to set up.
godot engage buttons with arrows
(works the same if you’re using a controller like Switch Pro or something)

2 Likes

It’s close, but what I want is for the arrows to appear outside the button

1 Like

Like this?
godot engage buttons with arrows 02

2 Likes

Yep, that’s it!

1 Like

you could put enough margins in the left and right patches of the 9-patch button graphic to put arrows there.
then use these margins to put arrows there when you want :slightly_smiling_face: