Art: sprites & portraits
Draw in Aseprite and Tiled; the engine reads their files directly. Saving in either program regenerates what the game uses.
Aseprite files
The game reads .aseprite files itself (no export step). On save (while the dev server runs, or with pnpm gen) it writes name.gen.png and a typed name.gen.ts next to the file. You import the .gen file.
- A file inside a folder called
sprites/orbattle_sprite/is an animated sprite. Any other.asepriteis a portrait. - The
.asepritefiles never ship in builds; importing one directly is an error on purpose. - Every layer is used, hidden or not: hide layers in Aseprite as you like while you paint. Layers named
_somethingare left out (sketches, guides). - Layers named
#somethingare rule layers: read, never drawn.#facemarks the face box of a portrait. - RGBA, grayscale and indexed files all work. Linked cels are fine.
- Languages: a layer named
<name>.<lang>(open.janext toOpen) is that layer in another language: words on a shirt, a sign in a CG. Capitals don't matter. Works in portraits, sprites and CGs; see Translations → per language.
Animated sprites (map)
import sprite from './sprites/jack.gen' // characters/jack/sprites/jack.aseprite
defineCharacter({ name: 'Jack', sprite })
// also: props, the player (content/config/player.ts uses the hero's), enemies, any map object with `sprite`
import battleSprite from './battle_sprite/wolf.gen' // enemies/wolf/battle_sprite/wolf.aseprite
defineEnemy({ name: 'Wolf', battleSprite, /* … */ }) // same for defineCharacter: see Battles
Tags = animations
| Tag name | Meaning |
|---|---|
idle_down, walk_right, talk_up … | state_direction. Directions: up, down, left, right. |
missing *_left | Uses *_right, mirrored |
wave (no direction) | The same for every direction |
| no tags at all | All frames become one idle animation |
- The engine uses
idle(standing),walk(moving) andtalk(while that character's line types in a scene). Other tags are yours toplay(). - Frame durations, ping-pong and repeat counts carry over. Repeat 0 (∞) loops; a looping animation keeps going until something else plays.
- Animation names become types:
npc('jack').play('wavee')is an error.
Slices = placement and collision
| Slice name | Meaning |
|---|---|
origin | The feet: its pivot point, or the bottom centre of the slice. Default: the bottom centre of the canvas. |
collision, collision_* | Hitbox (all of them together). Without one, the whole tile blocks. For the player it is the player's hitbox. |
interact | Where the player must face to talk/use. Default: the collision boxes. |
trigger, trigger_* | Walk-over areas for onEnter (pressure plates). They don't block. |
Only frame 1 of a slice counts. Collision isn't mirrored for left-facing sprites. Other slice names give a warning.
Portraits (scenes)
Four ways, from simplest to most flexible. A character has one of them (portraits, layered or spine), never two.
1. One image per pose
import neutral from './portraits/neutral.png'
import happy from './portraits/happy.png'
defineCharacter({ name: 'Anna', portraits: { neutral, happy } }) // first = default pose
The face box
Where the face is on a portrait: the side image and the Settings → Voices tiles show that square. In Aseprite, add a layer #face with a black filled square over the face (e.g. 100 × 100 at x 20, y 30). Hide it if you like: it is still read and never drawn. In code it can be set or overridden, most specific first:
layered: fromAseprite(portrait, {
defaults: { eyes: 'open', mouth: 'smile', faceArea: { x: 20, y: 30, w: 100, h: 100 } }, // overrides #face (or sets it)
expressions: {
neutral: {},
tilted: { eyes: 'open', faceArea: { x: 34, y: 28, w: 100, h: 100 } }, // this expression only
},
})
defineCharacter({ name: 'Ann', portraits: { neutral, happy }, faceArea: { x: 40, y: 10, w: 200, h: 200 } }) // simple portraits
Spine portraits: faceArea / faceAreas in fromSpine (below).
Order: the expression's faceArea → defaults.faceArea → the #face layer → the character's faceArea → the top of the portrait. Keep it square; a box that is not is fitted into a square (the Aseprite build warns).
2. Layered, from Aseprite (paper doll)
One file with swappable parts. Layer rules:
- Layers and plain groups (folders) are always drawn: the body. Hidden layers are drawn too (hiding in Aseprite only helps while you paint).
_namelayers are left out. - A layer named
#nameis a rule layer: read, never drawn (hidden or not).#faceis the face box. - A group named
@Eyesis a part; its children are the options (a layer, or a plain group for a multi-layer option). - Layer order is draw order. Names become ids: lowercase, spaces and dashes to
_(@Outfit→outfit). No@groups inside@groups.
layered: fromAseprite(jack, {
defaults: { eyes: 'open', mouth: 'smile', outfit: 'jacket' }, // parts not listed start hidden
expressions: { // = the poses
neutral: {},
happy: { eyes: 'happy', mouth: 'open' },
sad: { mouth: 'frown' },
},
blink: { layer: 'eyes', closed: 'closed' }, // random blinking
talk: { layer: 'mouth', open: 'open' }, // mouth flaps while the line types
// pixelated: true (default; crisp scaling)
})
In scenes: show('jack', { pose: 'happy' }), and swap single parts with show('jack', { parts: { outfit: 'hoodie' } }) (typed). Changing pose only resets the parts that pose sets, so an outfit change survives.
3. Layered, from images or an atlas
import { defineAtlas, defineLayeredPortrait } from '@/core/portrait/define'
const face = defineAtlas({ src: faceSheet, width: 200, height: 120, frames: { eyes_open: { x: 0, y: 0, w: 100, h: 32 }, mouth_smile: { … }, … } })
layered: defineLayeredPortrait({
width: 300, height: 600, base, // the body image
layers: {
eyes: { x: 110, y: 120, options: { open: face.eyes_open, closed: face.eyes_closed }, default: 'open' },
mouth: { x: 125, y: 170, options: { smile: face.mouth_smile, frown: face.mouth_frown } },
},
expressions: { neutral: {}, sad: { mouth: 'frown' } },
blink: { layer: 'eyes', closed: 'closed' },
})
Positions are in pixels of the base image; the portrait scales freely. Options can be an image URL, an atlas frame or { src, x, y }; null hides a layer. Anna and Jack both use Aseprite portraits (above).
4. Animated, from Spine
A character rigged and animated in Spine (runs on Windows, macOS and Linux). The game reads Spine's export, not the .spine project file (that one never ships; importing it is an error). In Spine: Export → Binary (recommended: smaller, faster) or JSON, with Pack atlas on. Put what it writes into the character's portraits/ folder:
src/content/characters/driver/portraits/
driver.skel (or driver.json) the skeleton
driver.atlas where each image is on the pages
driver.png the page(s)
driver.gen.ts made by the game: files, typed animation and skin names, the box
A portraits folder holds an Aseprite file or a Spine export, never both (the build stops and says so). Export with the same Spine version as the game's runtime (4.3): an export from another version is warned about, because the runtime may not read it.
import { fromSpine } from '@/core/portrait/spine'
import driver from './portraits/driver.gen'
spine: fromSpine(driver, {
expressions: { // pose name -> animation (typed from the export); first = default
neutral: 'idle',
happy: 'happy',
wave: { intro: 'wave_in', animation: 'wave', parts: { hat: 'cap' } }, // intro once, then wave loops; sets a part
},
talk: 'talk', // laid over the pose while their line types / their voice plays
blink: 'blink', // laid over now and then (or { animation, everyMs: [2000, 6000] })
parts: { // skins as parts: show('driver', { parts: { hat: 'party' } })
hat: { cap: 'hat/cap', party: 'hat/party', none: null },
outfit: { winter: ['outfit/coat', 'acc/scarf'], summer: 'outfit/shirt' }, // an option = one or more skins
},
defaults: { parts: { outfit: 'summer' } }, // else each part starts on its first option
faceArea: { x: 211, y: 206, w: 300, h: 300 }, // the face box, in portrait pixels
mix: 0.2, // seconds every bone takes to ease into a new animation (default 0.2)
mixes: { 'wave>idle': 0.5 }, // its own time for one pair (typed: both must be animations)
// box: { x, y, width, height } (Spine units)
})
- Changing pose never jumps: every bone eases from where it is into the new animation over
mixseconds (or the pair's own time inmixes). Attachment swaps (an eye or mouth image) switch at once, as in Spine. Spine keeps these times out of the export, so they are set here. - Intro, then loop ("1 2 3 4 5 6 7 5 6 7 5 6 7…"): make two animations in Spine, the intro (1-4) and the loop (5-7), and give the pose
intro. The intro plays once, the loop follows right after it (no crossfade between them unlessmixessets one, e.g.'wave_in>wave') and repeats. Spine has no loop-start marker in an export; two queued animations are its usual way. - Poses are animations on track 0.
talkplays on track 1 andblinkon track 2, over the pose. Key the mouth and eyes in every pose animation, so they come back right after talking or blinking. - Parts are skins. A skin can hold any number of attachments in any slots (meshes, weighted meshes, its own bones), so one option can be a whole outfit or prop. The export's
defaultskin is always on. Skins that swap the same thing use the same placeholder name in the slot (Spine's usual setup). Changing pose only resets the parts that pose sets. - Size: the portrait is the generated
box, where every animation and every skin fits, scaled to the portrait height like any other portrait.faceAreais measured from that box's top left corner, in Spine units. - Optional: the Spine runtime is only part of a game that has a Spine character, and it loads the first time one is shown. One hidden WebGL renderer draws every Spine portrait into its own canvas, so screenshots and save pictures include them.
- Licence: shipping a game with the Spine runtime needs a Spine Editor licence (Essential or Professional; Enterprise above $500k yearly revenue). Players need nothing.
In scenes nothing changes: show('driver', { pose: 'wave' }), driver:happy: … in a .vn file, the side image and Settings → Voices work like for any portrait. The demo: the bus driver at the end of the bad route (events/vn_demo/driver).
Tiled tilesets
- Keep tilesets as
.tsj(Tiled: Export As… → JSON tileset) or embed them in the map. Put the image next to it, e.g.src/content/tilesets/countryside.png. - Tile property
solid= true makes that tile block, wherever it's used. - Tile animations made in Tiled play on the map, all on one shared clock.
- Maps whose tile size suggests pixel art are drawn with crisp (nearest) scaling.
Other images
- Import images in TypeScript (
import icon from './icon.svg'); the build copies them and gives a URL. - Item icons are small (16×16) images or SVGs. SVGs need a
<title>(Biome checks accessibility). - Backgrounds and CG pictures: any image. See backgrounds and the gallery.
- The current art (characters, props, tiles, app icon) is placeholder art made by throwaway scripts. Replace the files and keep the names.
Layered CGs (variants)
One Aseprite file in src/content/gallery/<id>/ gives a CG whose layers turn on and off (the same works for a background with variants in src/content/backgrounds/<id>/, see the background library):
- Layers and folders are always drawn, hidden or not (
_nameis left out and#nameis never drawn, as for portraits). - A layer or folder named
+nameis a toggle: off unless a variant turns it on. Hide toggles in Aseprite while you paint if you like. Layer order is drawing order, so a toggle can sit under other layers (tears under hair). - Only normal blending is drawn. Output next to the file:
pond.gen.png(no toggles),pond.<toggle>.part.gen.pngper toggle (cut to its pixels, so a few tears are a tiny image and cost almost no memory), andpond.gen.tswith each layer's place.
// src/content/gallery/pond_memory/index.ts
import cg from './pond.gen' // from pond.aseprite (+full moon, +crying)
export default defineGallery({
title: 'By the pond',
image: cg,
variants: { // only these exist; order = gallery order
base: {}, // the plain picture (no toggles): only if you list it
full_moon: { full_moon: true },
'crying.full_moon': { crying: true, full_moon: true },
},
})
cg('pond_memory', 'base') // the plain picture (a named variant)
cg('pond_memory', 'crying.full_moon') // a variant (typed: a wrong name is an error)
A CG with variants must always name one: cg('pond_memory') is a type error. The plain picture is never added by itself: list base: {} to have it (in the gallery and in cg()). A picture without variants is used as cg('hill').
Each variant unlocks on its own when an event shows it. In Extras → Gallery each variant is a dot in the viewer (see Extras).
Big games: quality, sizes and memory
Settings are in src/content/config/media.ts. Keep working with PNG/JPG/WAV; the build converts them. There are two builds:
- Normal (
pnpm build): exactly your quality. Images become lossless WebP (every pixel the same, about 25-40% smaller). WAV/AIFF become FLAC (lossless, sounds the same, about half the size). Files that are already compressed (MP3, OGG, M4A, MP4…) are shipped as they are. - Lite (any build command +
--lite): for weaker devices. Pictures with aliterule are shrunk (half size by default) and lossy; every sound becomes Opus. Its files end in-lite.
export default defineMedia({
images: {
convert: [ // first match wins (paths inside src/content)
{ match: 'gallery/**', format: 'webp', lite: { scale: 0.5, quality: 85 } },
{ match: '**/backgrounds/**', format: 'webp', lite: { scale: 0.5, quality: 85 } },
{ match: '**', format: 'webp' }, // pixel art: lossless in both builds
],
thumbnails: { width: 480, quality: 80 }, // Extras → Gallery grid
memoryMB: { desktop: 1024, mobile: 256, browser: 512 },
},
audio: {
convert: [
{ match: 'audio/voice/**', format: 'flac', lite: { opusKbps: 48 } },
{ match: '**', format: 'flac', lite: { opusKbps: 96 } },
],
},
events: { preloadAhead: 3 }, // see events → look-ahead
})
- Only shrink pictures that are drawn scaled to the screen (CGs, event backgrounds: put those in a
backgroundsfolder). Tilesets, sprite sheets and portraits store their sizes in pixels, so they must keep their size. - Dev always serves your own files.
qualityon a normal rule makes it lossy there too;format: 'keep'ships the original;'avif'is smaller but slower to build. JPGs are always lossy. A converted file that would be bigger than the original is dropped. - Results are cached in
node_modules/.cache/game-media, so rebuilds only convert new or changed files. Sounds are converted with ffmpeg (theffmpeg-staticpackage, nothing to install). - WebP can't be over 16383 px on a side; such images are shipped as they are (with a warning).
- Memory: an image takes width × height × 4 bytes once loaded (a 2048×2048 tileset ≈ 16 MB), whatever its file size. The current map's images always stay loaded. Images of maps you left stay too, so going back is instant, until they pass
memoryMB; then the longest unused are freed. Pictures in events (backgrounds, portraits, CGs) are handled by the browser itself. - Keep single images reasonable: 4096×4096 is the safe maximum on phones.
- Git: art and sound are stored with Git LFS (
.gitattributes). Runpnpm setup:lfsonce per clone. - Packaging big games: see Building → big games.