+1 vote

Hi!

I wanted to ask if there is a way to show a popup menu and hide it by clicking on the same button? Most of the tutorials use one button to call the menu and another one to hide/close it. I'm wondering how to achieve the same thing with just one button.

in Engine by (17 points)

1 Answer

+1 vote

Sure. Really, you just need to toggle the visibility of the PopupMenu with each button click. So...

  • Add a PopupMenu to the scene
  • Add a TextureButton to the scene
  • Add the following script to the parent of the above-mentioned controls (or change the script to as necessary)
  • Wire the pressed signal of the button to the the below function

.

func _on_TextureButton_pressed():
    $PopupMenu.visible = !$PopupMenu.visible
by (10,866 points)

Wow that was quick!
And the best thing is: it worked! ;)
Such a simple line....
Thank you so much!

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.