Characters & NPCs
A character is one definition used everywhere: name and portraits in scenes, a sprite on the map, stats in the party, relationship points.
Defining a character
// src/content/characters/jack/index.ts
import { defineCharacter } from '@/core/define'
import { fromAseprite } from '@/core/portrait/aseprite'
import jack from './portraits/jack.gen'
import sprite from './sprites/jack.gen'
import battleSprite from './battle_sprite/jack.gen'
export default defineCharacter({
name: 'Jack',
color: '#90caf9', // name plate colour (and placeholder portrait)
blip: 'sfx/blip', // short typing sound for lines without a voice clip
// faceArea: { x, y, w, h }, // optional: where the face is (side image, Voices tiles); see art.html#face-box
sprite, // map sprite (Aseprite with tags)
battleSprite, // in battle (./battle_sprite/jack.gen); default: the map sprite
layered: fromAseprite(jack, { // portraits; or portraits: { neutral: url, happy: url }
defaults: { eyes: 'open', mouth: 'smile' },
expressions: { neutral: {}, happy: { eyes: 'happy', mouth: 'open' } },
blink: { layer: 'eyes', closed: 'closed' },
talk: { layer: 'mouth', open: 'open' },
}),
relationship: { start: 0, min: -50, max: 100 }, // optional
battle: { // optional: can join the party
base: { hp: 30, attack: 5, magic: 6 }, growth: { hp: 5, attack: 1 },
skills: ['heal', { skill: 'fire', level: 3 }], // from the start, or from a level / a finished quest
// elements: { fire: 0.5 }, immune: ['sleep'], // what hurts them less, statuses that never stick
},
})
| Field | More | |
|---|---|---|
name, color | Shown on the name plate (translated) | |
portraits or layered | Portraits in scenes; the keys are the poses (typed). Neither = a coloured placeholder. | Art |
sprite | The map sprite | Art |
battleSprite | Drawn in battle (else the map sprite) | Battles |
blip | Typing sound | Audio |
relationship | Start value and limits of their points | below |
battle | Stats, skills (also by level or quest), element rates and immunities as a party member | Party, skills |
game in them.Putting them on a map
Give a map object character. In Tiled, name the object (e.g. jack) and give it behaviour in the map's objects:
objects: {
jack: {
character: 'jack',
facing: 'left',
animation: 'idle', // start animation
speed: 3, // tiles per second for scripted walks
turnToPlayer: true, // look at the player while talking (default)
onInteract: ({ game }) => game.events.start('jack/hello'),
},
}
- The object's id is the character id, so
game.maps.npc('jack')finds it. - While their line types out in a scene, the NPC plays its
talkanimation (if the sprite has one). - Collision comes from the sprite's
collisionslice, or the whole tile without one. NPCs don't block while walking. - Not a character? Use
spritedirectly for animals, birds, anything animated.
Scripting NPCs
const jack = game.maps.npc('jack') // in map hooks: world.npc('jack')
await jack.walk({ up: 2 }, { right: 3, speed: 6 }, { down: 1 }) // tiles; speed per step
await jack.walkTo({ x: 10, y: 4 }) // around walls; false if it can't get there
await jack.play('wave') // any animation tag (typed for characters)
await jack.play('wave', { times: 2, facing: 'player' })
await jack.play('open', { hold: true }) // stay on the last frame
jack.idle(); jack.idle('sleep') // back to idle / make 'sleep' the new idle
jack.face('left'); jack.face('player')
jack.teleport({ x: 3, y: 3 }, 'down')
jack.speed = 4
jack.hide(); jack.show(); jack.hidden // hidden = not drawn, no collision, can't be talked to
jack.exists; jack.x; jack.y; jack.facing
void jack.bark('Over here!') // speech bubble (below)
- Scripted walks ignore collision: you choose the path (
walkTofinds one around walls). - A handle looks the NPC up on every call: it stays valid across map changes and does nothing (with one warning) if the NPC isn't on the map.
- Positions after scripted walks are not saved; re-entering the map resets them (or the schedule places them).
- While replaying a saved scene, walks and animations finish instantly.
The player and the camera
await game.maps.player.walk({ left: 2 }) // player input is paused meanwhile
await game.maps.player.walkTo({ x: 5, y: 9 })
game.maps.player.face('up')
await game.maps.player.bark('Hmm…')
await game.maps.camera.follow('jack') // follow an NPC
await game.maps.camera.panTo({ x: 12, y: 6 }) // look at a tile
await game.maps.camera.reset() // back to the player (default 600 ms each)
Walking there in a script doesn't fire onEnter of objects on the way.
Speech bubbles
void jack.bark('Nice weather today.')
await game.maps.player.bark('Hmm…', { duration: 2000 }) // resolves when it disappears
- Text is translated; markup tags are removed.
- Default time depends on the length (1.5–6 s;
bubble.timeinsrc/content/look/map.ts). A new bark replaces that speaker's old one. Changing map clears them. - Their look (colours, font, padding, the point, fade):
src/content/look/map.tsbubble. Name labels and the "press A" prompt over the player are set there too. - Example: the town's
setupmakes Jack call out every 10–18 seconds when no scene is running.
Emote balloons
await world.npc('jack').emote('surprise') // resolves when it is gone
await world.player.emote('question', { duration: 2000 })
game.maps.player.emote('love') // from anywhere
// src/content/emotes.ts — add a line and its name works (and autocompletes)
list: { surprise: { text: '!', color: '#d32f2f' }, sleep: 'z Z', /* … */ },
Included: surprise, question, love, anger, sweat, idea, music, sleep, dots, happy. Size, how long they stay and the balloon colours are in the same file.
Schedules
Where an NPC is by time of day, per map:
jack: {
character: 'jack',
schedule: [
{ from: '8', at: { x: 14, y: 9 }, facing: 'left' },
{ from: '12:30', at: { x: 9, y: 11 }, facing: 'down', animation: 'idle' },
{ from: '17', at: { x: 14, y: 9 }, walk: false }, // jumps instead of walking
{ from: '21:30', at: { x: 31, y: 10 }, hidden: true }, // walks off, then is gone
],
}
from:'8','08:30'or8.5. When it comes, the NPC walks toataround walls.- Entering the map puts NPCs straight where their schedule says. Before the day's first entry, the last one still applies (so night lasts until morning).
- The clock stops while you talk or interact (see time of day), so an NPC never walks off mid-conversation.
- A walking NPC can't be talked to (no prompt either) until it stops.
- The maps test checks that every schedule spot is on a walkable tile.
Names that change
A character can start hidden and change name during the story. Set unknownName and the game shows it until it is revealed:
// characters/god/index.ts
export default defineCharacter({ name: 'God', unknownName: '???' })
// in an event (from its context): any text as a fake name, changed as often as you like
rename('god', 'Stranger')
// the real name, from now on
reveal('god')
// anywhere else
game.characters.rename('god', 'Evil God'); game.characters.reveal('god')
game.characters.name('god') // what is shown now (translated)
game.characters.known('god') // false while the name is still hidden
game.characters.forget('god') // back to the start
const name = useCharacterName('god') // React, from '@/core/managers/characters'
- The shown name is saved with the game and used for every line they say from then on. Lines already in the log keep the name they were said with.
- For one line only, use the line style
as:say('god', '…', { as: 'A voice' }). - In
.vnscripts:rename god "Evil God"andreveal god.
Relationships
Points per character: how much they like the player.
game.relationships.get('anna') // the character's start value at first
game.relationships.change('anna', 5, { notify: true }) // toast "♥ Anna +5"; returns the new value
game.relationships.set('anna', 20)
game.relationships.all() // { anna: 20, jack: 0, … }
const points = useRelationship('anna') // React, from '@/core/managers/relationships'
Saved with the game and kept within the character's min…max (default −100…100). Use them in scenes, e.g. a choice that is disabled until Anna likes you enough. In .vn scripts: love anna +3 and if love('anna') >= 10:.