Hide and Show
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 23 of 28.
visible is true when a node is shown and false when it is hidden. A hidden node hides its children too. hide() and show() do the same as setting it:
$Mouth.visible = false # or $Mouth.hide()not turns true into false and back. So bulb.visible = not bulb.visible hides the bulb if it was shown, and shows it if it was hidden.
To blink, switch on a clock. A node variable that adds up delta counts seconds. When it reaches your time, switch, and take that time off the clock:
timer += delta
if timer >= 1.0:
timer -= 1.0
print("tick")That prints tick once a second.
Challenge
EasyMake the bulb on the robot's antenna blink.
- In
_process(), adddeltatotimeron every frame. - When
timerreaches0.5, take0.5off it and switchbulb.visible.
Press Play: the bulb starts lit, then goes off and on every half second. Then Check.
Try it yourself
extends Node2D
@onready var bulb = $Bulb
var timer = 0.0
func _process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Nodes and Scenes
Practice on your own: Godot playground