how to properly use hide() show() ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By friendlyapprentice
:warning: Old Version Published before Godot 3 was released.

I’m a total noob. it’s like every time I try to script anything it won’t work…

Example, how would I set the visibility on a sprite using button?

extends Panel

func _on_button_pressed():
    get_node("Sprite").set_visible()

func _ready():
    get_node("Button").connect("pressed",self,"_on_button_pressed")

So that won’t do anything …

And also what does the (self) mean? Thanks …

:bust_in_silhouette: Reply From: volzhs
extends Panel

func _on_button_pressed():
    get_node("Sprite").set_hidden(!get_node("Sprite").is_hidden())

func _ready():
    get_node("Button").connect("pressed",self,"_on_button_pressed")

self means current instance, it is same with this in another languages.

Wow… so let me try to understand…
the last line ‘connect’ the pressed state of “button” with the function declared at second line. It connect the function to a trigger. Ok.

But what is " !get_node(“Sprite”).is_hidden() " doing exactly ?
Is it a way to flip/flap visible and hidden according to current state of the “Sprite” ?

( Just starting with Godot, aka total noob as would say friendlyappretice )

Graphitik | 2017-09-05 00:51

Thanks for the reply @volzhs. And yep Graphitik it is to do as you’ve written

friendlyapprentice | 2017-09-05 01:13