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.

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 nameMeaning
idle_down, walk_right, talk_up …state_direction. Directions: up, down, left, right.
missing *_leftUses *_right, mirrored
wave (no direction)The same for every direction
no tags at allAll frames become one idle animation

Slices = placement and collision

Slice nameMeaning
originThe 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.
interactWhere 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.

Turn on collision in the dev panel to see every box on the map: red walls, orange NPC boxes, green triggers, blue interaction areas, cyan player hitbox.

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:

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)
})

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

Other images

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):

// 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:

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
})