The warrior you have played since lesson 1 is one frame of a picture file. See how sprites work, then swap in any character you like.
Loading the game engine. This takes a moment the first time.
The warrior you have been playing since lesson 1 is not something Godot draws on its own. It is a picture file, shown by a Sprite2D node in the player scene. This lesson opens that up: how the picture gets on screen, why one file secretly holds eight poses, and how to swap in any character you like without touching a line of code.
Look at warrior_idle.png in the FileSystem dock: it is 1536 pixels wide, but the warrior is only 192. The file is a spritesheet of eight drawings packed side by side. Setting "hframes" to 8 on the Sprite2D slices it into eight frames, and "frame" picks which one is showing. We sit on frame 0. Playing the frames in order is what Simple Animation is about.
Now look at the two big knights on the right of the game. Same file, same size, but one is smeared and one is sharp. When a picture is drawn bigger than its file really is, Godot has to invent the missing pixels, and the texture filter is HOW it invents them. Linear blends neighbouring pixels together, right for smooth, painted art. Nearest repeats each pixel as a chunky block, right for pixel art. Blow up pixel art with Linear and you get the blurry knight on the left.
Both characters are free-to-use art packs. The warrior is from Tiny Swords and the knight from the Brackeys pack. The website's Assets page has both packs in full, plus plenty more to build with.
■ UI node · ■ 2D node · % unique name · .tscn instanced scene
extends Node2Dextends CharacterBody2D
## Same speed, same meaning as lesson 1.
@export var speed: float = 200.0
# The sprite is a child node of the player, so the picture follows the body
# automatically. We only need our own handle on it for the flip below.
@onready var sprite: Sprite2D = $Sprite2D
func _physics_process(_delta: float) -> void:
var direction: Vector2 = Input.get_vector(
"move_left", "move_right", "move_up", "move_down"
)
velocity = direction * speed
move_and_slide()
# The sheet only has a warrior facing RIGHT. Instead of asking an artist
# for a left-facing copy of every drawing, mirror the picture whenever we
# walk left. Standing still keeps whichever way we faced last.
if direction.x != 0.0:
sprite.flip_h = direction.x < 0.0