Hide and Show
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 23 of 27.
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. It starts lit, then switches every half second: off, on, off, on. Use the timer variable as a clock. The rest of the robot stays visible.
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