Scenes and nodes
A Gaminode game is a tree of nodes. Each node does one job, and a scene is a tree of nodes saved to a file that you can reuse anywhere, as many times as you like.
Nodes
A node has a name, a type, settings in the Inspector, and children. The type decides what it does. You build anything by combining simple nodes:
A playerPlayer (CharacterBody2D) moves and collides
├── Sprite2D draws the picture
├── CollisionShape2D gives it a body
├── AnimationPlayer plays animations
└── Jump (AudioStreamPlayer) plays a sound
Scenes
Save a node tree as a .tscn file and it becomes a scene. A scene can be a whole level or one bullet. You put scenes inside other scenes by instancing them: drag the .tscn from FileSystem into the viewport, or press the chain-link button in the Scene panel.
Change the original scene and every instance follows. Change one instance in the Inspector and only that one changes.
Spawning a scene from codeconst BULLET := preload("res://bullet.tscn")
func shoot() -> void:
var b := BULLET.instantiate()
b.global_position = global_position
get_parent().add_child(b)
Node types you'll use most
| Node | For |
|---|---|
Node2D / Node3D | A position in 2D or 3D space; good as a root or a folder |
Sprite2D, AnimatedSprite2D | Pictures and frame animations |
MeshInstance3D | A 3D model |
CharacterBody2D/3D | Players and enemies you move from code with move_and_slide() |
RigidBody2D/3D | Things moved by physics: balls, crates |
StaticBody2D/3D | Floors and walls |
Area2D/3D | Trigger zones and pickups: tells you when something enters |
CollisionShape2D/3D | The shape of a body or area (every body needs one) |
Camera2D/3D | What the player sees |
Timer | Do something every few seconds |
AudioStreamPlayer | Music and sounds |
Control, Label, Button, VBoxContainer | Menus and the HUD |
CanvasLayer | Keeps the HUD on top and still while the camera moves |
Signals
A signal is a message a node sends when something happens. Connect it in the Node tab next to the Inspector, or in code:
func _ready() -> void:
$Button.pressed.connect(_on_play_pressed)
$Coin.body_entered.connect(_on_coin_touched)
func _on_play_pressed() -> void:
get_tree().change_scene_to_file("res://scenes/Main.tscn")
Make your own with signal died and send it with died.emit().
Groups
Groups are labels on nodes, for finding many at once. Add one in Node > Groups or with add_to_group("enemies").
for e in get_tree().get_nodes_in_group("enemies"):
e.queue_free()
The main scene
The main scene is the one F5 and exported games start with. Set it in Project > Project Settings > Application > Run. Health Check warns you if it's missing.
Something wrong or missing on this page? Email gaminodeofficial@gmail.com.