Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | dezekeerjoran | |
Old Version | Published before Godot 3 was released. |
How do you make a button, that is always presed until you press it again?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | dezekeerjoran | |
Old Version | Published before Godot 3 was released. |
How do you make a button, that is always presed until you press it again?
Reply From: | Nutr1z |
Hi,
What you are saying is named toggle mode, see BaseButton.set_toggle_mode().
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)
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 = get_node(“textureButton”)
Button.set_toggle_mode(true)
(I have connect the button)
func _on_TextureButton_pressed():
var voiceID = SFX_player.play(“jump”, false)
SFX_player.set_volume(voiceID, 0.0)
update()
`
thanks for helping!
dezekeerjoran | 2017-03-01 17:47
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)
Jowan-Spooner | 2018-12-21 17:56