Manual Ship

On this page
  1. Sprite frames
  2. A playable scene
  3. Scene kinds
  4. The actor script
  5. Where the files live
  6. Terrain, UI and palette swaps
  7. Lit sprites
  8. Run it
  9. Pitfalls
  10. Next

Godot 4

SpriteFrames, a playable character scene with gameplay boxes, TileSets, UI themes, palette swaps and lit sprites for Godot 4, crisp at any res:// path.

Godot 4 gets the most from Mode 8: SpriteFrames for any sprite, a ready character scene with its collision body and attack hitbox, TileSets with collision for terrain, a theme for the UI kit, a palette-swap shader and normal maps for 2D lights. Every resource refers to its PNGs by a path relative to itself, so you can drop an export folder anywhere under res://, and every texture is set to nearest filtering, so pixels stay crisp in a default project.

To follow along, make a starter project. Its godot/ folder is a Godot 4 project that already uses all of this:

bash
mode8 init my-game --template platformer
cd my-game
The platformer starter's hero scene in Godot 4 with Visible Collision Shapes on: the body at the feet, the attack hitbox in front of the sword
hero.tscn in a test room, collision shapes visible

Sprite frames#

The default export already includes Godot. hero.tres is a SpriteFrames resource with one animation per name, each with its speed and loop setting:

terminal
$ mode8 export assets/hero/frames --out-dir exports/hero --name hero --animations assets/hero/master.m8.json
✓ Exported hero (15 frames) → exports/hero/
  atlas, godot, gif · 9 files
  animations attack, hurt, idle, jump, walk
  preview exports/hero/hero.gif + one GIF per animation (5)
    Godot exports/hero/hero.tres
  palette nes_master_gothic from mode8.toml

Next:
  mode8 verify --assets-dir exports/hero

Drag hero.tres onto the Sprite Frames property of an AnimatedSprite2D, or load it in code:

gdscript
$AnimatedSprite2D.sprite_frames = load("res://art/hero/hero.tres")
$AnimatedSprite2D.play(&"walk")

The atlas inside is wrapped in a CanvasTexture with nearest filtering, so the sprite stays sharp even when the project's default texture filter is linear.

A playable scene#

Add godot_scene and Mode 8 writes a scene you can instance and play:

terminal
$ mode8 export assets/hero/frames --out-dir godot/art/hero --name hero --formats godot,godot_scene --animations assets/hero/master.m8.json
✓ Exported hero (15 frames) → godot/art/hero/
  godot, godot_scene · 4 files
  animations attack, hurt, idle, jump, walk
  Godot godot/art/hero/hero.tres
  scene godot/art/hero/hero.tscn (CharacterBody2D, mode8_actor.gd)
  palette nes_master_gothic from mode8.toml

Next:
  mode8 verify --assets-dir godot/art/hero
$ grep '^\[node' godot/art/hero/hero.tscn
[node name="hero" type="CharacterBody2D"]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="Hitbox" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]

The hero's scene is a CharacterBody2D:

  • AnimatedSprite2D plays the SpriteFrames and autoplays idle. Its offset puts the pivot at the node's origin, so the scene's position is where the feet stand.
  • CollisionShape2D is the body: a rectangle fitted to the feet and torso of the idle frame, the right shape for walking on floors and stairs.
  • Hitbox is an Area2D with the attack's damage area. The AnimationPlayer switches it on only on the frames that strike (attack here) and off again.
  • mode8_actor.gd is the script on the root (see below).

When you also export the atlas, its JSON gets a boxes section: the pivot, the body, a collision polygon, and for every frame a hurtbox (where it can be hit) and a hitbox (where it hits, or null). Use it for your own hit detection, or in another engine.

Scene kinds#

--scene-kind picks the root node. The default, auto, makes a character when the frames have actor animations (idle, walk, attack and so on) and a plain sprite otherwise:

--scene-kindRootFor
characterCharacterBody2D with body, hitbox and actor scriptheroes, enemies, NPCs
staticStaticBody2D with a collision shapecrates, chests, doors: things you bump into
spriteNode2D, no physicstorches, decorations, background props
terminal
$ mode8 export assets/chest/master.png --out-dir godot/art/chest --name chest --formats godot,godot_scene --scene-kind static
✓ Exported chest (1 frame) → godot/art/chest/
  godot, godot_scene · 3 files
  animations master
  Godot godot/art/chest/chest.tres
  scene godot/art/chest/chest.tscn (StaticBody2D)
  palette nes_master_gothic from mode8.toml

Next:
  mode8 verify --assets-dir godot/art/chest

The actor script#

mode8_actor.gd is written next to every character scene. It plays idle on start, mirrors the sprite, the body and the hitbox together when the character turns, runs one-shot animations (attack, hurt) and returns to idle after them, and applies gravity when you set it. Each export rewrites it, so extend it rather than editing it:

gdscript
extends "res://art/hero/mode8_actor.gd"

func _physics_process(delta: float) -> void:
	if not is_on_floor():
		velocity.y += 980.0 * delta
	var dir := Input.get_axis("ui_left", "ui_right")
	velocity.x = dir * 120.0
	face(dir)
	move_and_slide()
	if Input.is_action_just_pressed("ui_accept"):
		play_animation(&"attack")

play_animation(name), face(direction) and the animation_done(anim) signal are the whole interface. The starter's godot/player.gd is a complete platformer controller built the same way. Pass --no-actor-script to get the scene without the script.

Without a part map, the hurtbox is the silhouette minus its outline and the hitbox is the leading edge of the attack frame, on the side the art faces. With --parts (the part map, plus --master, the image it was painted on) the hurtbox covers the head and body parts and the hitbox the weapon or front arm. For art that faces left, pass --facing left so the hitbox lands on the right side, and tick Art Faces Left on the script.

Where the files live#

By default every resource names its PNGs by a path relative to itself (path="hero_atlas.png"), so an export folder works wherever you put it in the project. If your project needs absolute paths, pass the folder the files will be imported under:

terminal
$ mode8 export assets/hero/frames --out-dir exports/hero --name hero --formats godot --godot-res-prefix res://art/hero
✓ Exported hero (15 frames) → exports/hero/
  godot · 2 files
  animations attack, hurt, idle, jump, walk
  Godot exports/hero/hero.tres
  palette nes_master_gothic from mode8.toml

Next:
  mode8 verify --assets-dir exports/hero
$ grep ext_resource exports/hero/hero.tres
[ext_resource type="Texture2D" path="res://art/hero/hero_atlas.png" id="1_atlas"]

--godot-res-prefix works the same on autotile, ui and recolor.

Terrain, UI and palette swaps#

Other commands write Godot resources too. Each has its own page:

  • TileSets. mode8 autotile ... --formats godot writes a TileSet with the terrain's peering bits and a physics layer, ready to paint in a TileMapLayer (--occluders adds a light-occluder layer). See Terrain and props.
  • UI themes. mode8 ui writes a StyleBoxTexture per 9-slice piece, a Theme that wires them and the pixel font to Godot's controls, and a health bar scene. See UI and fonts.
  • Palette swaps at run time. mode8 recolor --shader --variants ... writes a palette-swap shader, its lookup texture and a ShaderMaterial, so one sprite can wear several palettes. See Palettes.

For example, a ground TileSet at the starter's 32 px tile size:

terminal
$ mode8 autotile ground_top --out-dir godot/art/ground --name ground --size 32x32 --formats godot
✓ Autotile ground: 16 blob16 tiles (32x32) → godot/art/ground/
  sheet godot/art/ground/ground_autotile.png
  side view (lip on top) · organic edges · 8 interior variants
  Godot TileSet godot/art/ground/ground.tres (physics)
  palette nes_master_gothic from mode8.toml

Lit sprites#

Add normal and emission and the scene is ready for Light2D nodes: it switches to hero_lit_frames.tres (the same frames with a normal map) and adds an Emission overlay that keeps the glowing pixels bright in the dark:

terminal
$ mode8 export assets/hero/frames --out-dir godot/art/hero --name hero --formats godot,godot_scene,normal,emission --animations assets/hero/master.m8.json
✓ Exported hero (15 frames) → godot/art/hero/
  godot, godot_scene, normal, emission · 10 files
  animations attack, hurt, idle, jump, walk
  Godot godot/art/hero/hero.tres
  scene godot/art/hero/hero.tscn (CharacterBody2D, mode8_actor.gd)
  lit SpriteFrames godot/art/hero/hero_lit_frames.tres · relief 2
  palette nes_master_gothic from mode8.toml

Next:
  mode8 verify --assets-dir godot/art/hero

Lighting covers both maps and how to tune them.

Run it#

Open the project in the Godot 4 editor (it imports the art the first time), then press F5:

bash
godot -e --path godot

To check a scene without opening the editor, mode8 verify renders it headless with Godot and saves the frame as render.png in a hidden folder of the project (the report prints the path), for CI or a quick look. Run it from the project folder; it needs Godot 4 on the machine (--godot-bin or GODOT_BIN points at it):

mode8 verify --godot-project godot --render-scene res://main.tscn --render-frame 3

--render-frame picks the frame to capture, at 60 frames a second. Add --render-golden PNG to compare the render with a frame you saved: any differing pixel fails the check (exit 1), unless --render-max-diff allows that many. Checks covers verify in full.

Pitfalls#

  • Blurry sprites come from textures made outside Mode 8. Mode 8's resources set nearest filtering themselves; for your own textures, set Rendering > Textures > Default Texture Filter to Nearest.
  • An edit to mode8_actor.gd disappears on the next export. Put your code in a script that extends it.
  • The hitbox is on all the time. Play attacks with play_animation(), which runs them through the AnimationPlayer that switches the hitbox; $AnimatedSprite2D.play() alone does not.

Next#