+1 vote

How do you make a button, that is always presed until you press it again?

in Engine by (55 points)

1 Answer

+1 vote

Hi,

What you are saying is named toggle mode, see BaseButton.settogglemode().

Set the button toggle_mode property. Toggle mode makes the button flip
state between pressed and unpressed each time its area is clicked.

You can enable it by selecting a node Button (or whatever node inherited from BaseButton), and in the inspector : BaseButton > Toggle Mode.

You can also doing that with GDscript : get_node("MyButton").set_toggle_mode(true)

by (370 points)

sorry but, it doesn't work. i will give a little more info:

I am trying to make a checkbutton that toggles music. I have:

`extends RigidBody2D

var player
var Button

func ready():
player = get
node("streamplayer")
Button = getnode("textureButton")
Button.set
toggle_mode(true)
(I have connect the button)

func onTextureButtonpressed():
var voiceID = SFX
player.play("jump", false)
SFXplayer.setvolume(voiceID, 0.0)
update()
`

thanks for helping!

Use the Buttons signal toggled(bool) and connect it to a function like this:

func on_Texture_Button_toggled(bool):
    if bool == true:
        player.volume = 0.0
    elif bool == false:
        player.volume = 1.0

Hope it will help. (Code is for Godot 3.0)

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 Frequently asked questions and 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 [email protected] with your username.