Characters and Sprites
A character in Monogatari is a name the text box shows, a color for that name, and the pictures that go with them: sprites, the full-size pictures that stand on the scene, and side images, the small faces next to the text. This page goes from declaring a character to moving them around the stage.
Everything here is done in two places: the image files go in the assets/characters folder of your game, and the declarations go in js/script.js.
Declare a character
Characters are declared with monogatari.characters() in js/script.js. The starter game already declares one:
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
},
});'y'is the character’s id: the word your script uses for them, as in'y Hello!'. Keep it short, since you type it on every line.nameis what the text box shows above their lines.coloris the color of that name: any CSS color, like'#5bcaff'or'crimson'. Without it, the name takes the color of the--character-name-colorCSS variable, white in the starter game.
Add more characters to the same object, each with its own id:
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
},
'm': {
name: 'Mio',
color: '#ff8aa8',
},
});Ids are case-sensitive, and each must be different. Don’t use a word that starts a statement, like play, stop or wait, as an id: 'wait Are you there?' runs the wait action instead of a line. With the debug module, an error dialog names any character whose id is one of those words when the game starts. A line that starts with an action’s word lists them.
Add sprites
Put the character’s pictures in a folder of their own inside assets/characters, one file per expression:
assets/
characters/
yui/
happy.png
smiling.png
worried.png
angry.pngPNG files with a transparent background work best, so the scene shows around the character. Then tell Monogatari where they are and give each one a name:
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
directory: 'yui',
sprites: {
happy: 'happy.png',
smiling: 'smiling.png',
worried: 'worried.png',
angry: 'angry.png',
},
},
});directoryis the character’s folder insideassets/characters. Without it, the files are read fromassets/charactersitself.spritespairs a name, which your script uses, with a file name. The two don’t have to match:angry: 'yui-frowning-v2.png'is fine.
File names are case-sensitive once the game is online: Happy.png and happy.png are different files on most web servers.
Show a character
show character puts a sprite on the scene: the character’s id, then the name of the sprite.
'Start': [
'show scene afternoon',
'show character m happy at left',
'show character y happy at right',
'y:smiling Hi, Mio! Did you finish your drawing of the palace?',
'end',
],
at says where the character stands:
| Position | Where |
|---|---|
at left |
Against the left edge. |
at center |
In the middle. A show character statement without at puts the character here. |
at right |
Against the right edge. |
with adds an animation as the character appears: 'show character y happy at left with fadeIn'. The animations are the classes of Animate.css 4, written without its animate__ prefix (fadeIn, bounceIn, slideInLeft…), and duration 2s after the animation sets how long it takes.
A character must have sprites before it can be shown. A sprite name the character doesn’t have (or a character with no sprites), or an id that isn’t declared, opens a dialog that says so, and the next click goes on past that statement. Show Character lists everything a show character statement can take.
Change a character’s expression
Show the character again with another sprite. The new sprite takes the old one’s place:
'show character y happy at right',
'y I have a surprise for you.',
'show character y smiling at right',
'y Happy birthday!',WARNING
Repeat the position every time. A show character statement without at puts the character in the center, even when they were standing somewhere else: 'show character y smiling' would move Yui from the right to the middle of the screen.
Move a character across the stage
Add move to make the character slide to the new position instead of appearing there, and transition to say how long the move takes:
'show character y happy at left',
'y I am over here...',
'show character y happy at right with move transition 3s',
'y ...and now I am over here.',Without transition, the move takes 0.2 seconds, the value of the --character-move-speed CSS variable.
Hide a character
'hide character y with fadeOut',Without an animation, the sprite leaves at once. show scene takes every character off the stage, so you don’t need to hide them before a new scene. Hiding a character who isn’t on stage opens a dialog that says so, and the game skips the statement.
A show character statement can also set up the animation the character leaves with, with end- before its name: after 'show character y happy at left with fadeIn end-fadeOut', a plain 'hide character y' fades Yui out. Hide Character has the details.
Show a side image in the text box
A side image is a small picture, usually the character’s face, that the text box shows next to their line. Put the files in the character’s folder, in a folder of their own if you like:
assets/
characters/
yui/
happy.png
worried.png
expressions/
happy.png
smiling.png
worried.pngDeclare them with expressions, the same way as sprites. The file names are relative to the character’s directory, so they include the expressions/ folder:
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
directory: 'yui',
sprites: {
happy: 'happy.png',
worried: 'worried.png',
},
expressions: {
happy: 'expressions/happy.png',
smiling: 'expressions/smiling.png',
worried: 'expressions/worried.png',
},
default_expression: 'happy',
},
});Name the expression in the line, after the id and a colon:
'y:smiling Morning!', // the smiling side image
'y:worried I lost my scarf.', // the worried one
'y Have you seen it?', // the default_expression: happydefault_expressionis the side image of every line that doesn’t name one: the name of one of the character’sexpressions, or a file in the character’s folder. Without it, those lines have no side image.- A line that names an expression the character doesn’t have shows no side image, and no error.
- A side image doesn’t change the sprite on the stage, and the sprite doesn’t change the side image: change both when the character’s mood changes.
- Lines on an NVL page don’t show side images.
A character who always speaks in NVL
Give a character nvl: true and every line of theirs goes on the full-screen page of text, with their name in front of it, instead of in the text box at the bottom:
'n': {
name: 'Narrator',
nvl: true,
},Show a page of text explains NVL mode. For a character whose lines shouldn’t type out letter by letter, add type_animation: false.
Build a character from layers
WARNING
Layered sprites are experimental: they need 'ExperimentalFeatures': true in js/options.js, and may change in a later version. Add the setting inside monogatari.settings({ … }); the starter game’s file doesn’t have it yet.
Instead of one picture per expression, a layered character is drawn from parts stacked on top of each other: a body, then clothes, then a face. Change one part and the rest stay.
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
directory: 'yui',
// The layers, from back to front
layers: ['base', 'clothes', 'face'],
// The pictures each layer can show
layer_assets: {
base: {
body: 'base-body.png',
},
clothes: {
uniform: 'clothes-uniform.png',
casual: 'clothes-casual.png',
},
face: {
neutral: 'face-neutral.png',
happy: 'face-happy.png',
},
},
// A layered sprite names one picture per layer
sprites: {
school: { base: 'body', clothes: 'uniform', face: 'happy' },
happy: 'happy.png',
},
},
});'show character y school at left'shows the whole layered sprite, like any other sprite.'show character y:face neutral'changes only the face.'hide character y:face'takes one layer off.
Every layer picture has the size of the whole character, with transparent space around the part it draws, so the layers line up. Character Layers has every detail.
The properties of a character
| Property | Type | What it does |
|---|---|---|
name |
text | The name the text box shows. It can hold a variable, like '{{player.name}}'. |
color |
text | The CSS color of the name. |
directory |
text | The character’s folder inside assets/characters. |
sprites |
object | The sprites: a name for each, and its file, or an object of layers for a layered sprite. |
expressions |
object | The side images: a name for each, and its file. |
default_expression |
text | The name of the side image for lines that don’t name one. |
nvl |
true or false |
Whether every line of the character goes on the NVL page. false unless you set it. |
type_animation |
true or false |
Whether the character’s lines type out letter by letter. true unless you set it. |
layers |
list | Experimental. The layers of a layered sprite, from back to front. |
layer_assets |
object | Experimental. The pictures each layer can show. |
A complete character
A character with sprites, side images and a default side image, ready to paste into js/script.js and adapt:
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
directory: 'yui',
sprites: {
happy: 'happy.png',
smiling: 'smiling.png',
worried: 'worried.png',
},
expressions: {
happy: 'expressions/happy.png',
smiling: 'expressions/smiling.png',
worried: 'expressions/worried.png',
},
default_expression: 'happy',
},
});
monogatari.script({
'Start': [
'show character y smiling at center with fadeIn',
'y:smiling Hi! I\'m Yui. Nice to meet you!',
'show character y worried at center',
'y:worried ...but I have to go now.',
'hide character y with fadeOut',
'end',
],
});Related
- Show Character, Hide Character and Character Layers: the statements, in full.
- Writing Dialog: make your characters speak.
- Scenes and Images: the scene the characters stand on.