The scene is the picture behind everything: a palace, a street, the night sky. Over it go the characters, and any other picture the story needs, like a letter or a photo. This page shows how to add both to your game and change them as the story goes.

Add a scene

Put the picture in the assets/scenes folder of your game:

assets/
  scenes/
    afternoon.jpg
    night.jpg

Declare it in js/script.js, in the monogatari.assets('scenes', { … }) call the starter game already has. Each entry pairs a name, which your script uses, with the file name:

monogatari.assets('scenes', {
  afternoon: 'afternoon.jpg',
  night: 'night.jpg',
});

Then show it from the script:

'Start': [
  'show scene afternoon with fadeIn',
  'The drawing class had ended an hour ago.',
  'end',
],

Any picture a browser shows works: PNG, JPG, WebP or SVG. The picture covers the whole game screen behind the text box, centered. When its shape differs from the screen’s, its edges are cropped: a picture in the shape of the screens you expect, like 1920 × 1080 for a 16:9 screen, loses the least.

What a new scene clears

show scene starts a fresh stage. Along with the background, it takes away:

  • every character, and every image shown with show image;
  • the text on screen, including a page of NVL text.

Music, sound and voice keep playing.

When you only want a different background, and the characters should stay, use show background instead:

'show scene afternoon',
'show character y happy at right',
'show background night with fadeIn',
'y Look how fast it got dark.',

Yui stays on the right while the background changes behind her. Show Scene and Show Background have the details.

Use a color as the scene

A CSS color works as a scene, with no picture to declare, and so does a gradient:

'show scene #101418',
'show scene rgb(240, 236, 228) with fadeIn',
'show scene black with fadeIn',
'show scene linear-gradient(#ffd6a5, #a0c4ff)',

A word that is neither a declared scene nor a color, like a misspelled scene name, leaves the screen black behind the text box, and no error dialog opens. Check the spelling against your monogatari.assets('scenes', { … }) call when that happens.

Change scenes with an animation

with and an animation’s name play that animation on the new scene as it appears:

'show scene afternoon with fadeIn',
'show scene night with fadeIn duration 3s',

The animations are the classes of Animate.css 4, written without its animate__ prefix: fadeIn, zoomIn, slideInLeft and the rest. duration and a time after the animation set how long it takes. The new scene replaces the old one at once and the animation plays on it, so fadeIn fades it in from the black of the empty screen, not from the old scene.

Show a picture over the scene

Pictures that aren’t scenes or characters (a letter, a photo, a map) go in assets/images:

assets/
  images/
    note.svg

Declare them with monogatari.assets('images', { … }) in js/script.js:

monogatari.assets('images', {
  note: 'note.svg',
});

Show and hide them from the script:

'Start': [
  'show scene afternoon',
  'show image note at right with fadeIn',
  'A folded note was tucked into my sketchbook.',
  'hide image note with fadeOut',
  'end',
],

The palace in the afternoon, with a handwritten note on the right that says Meet me by the lamps when they light up
An image shown at right over the scene.

  • at places the image: left, right, top or bottom puts it against that edge, and without at it’s in the middle.
  • with takes the same animations as scenes and characters.
  • Showing an image that is already on screen adds a second copy of it, and hide image then hides both.
  • Hiding an image that isn’t on screen opens a dialog that says so, and the game skips the statement.

Show Image and Hide Image have the details.

Load pictures before they’re needed

With the game served, Monogatari loads every scene, image and character picture you declared while the loading screen shows, so none of them pops in late during play (the 'Preload': true setting in js/options.js). Opened from a file, some of this doesn’t work: What works opened from a file says what. Asset Preloading explains the setting.

Videos, particles and canvases

The scene can hold more than pictures:

  • Show Video: a video as the background, over the scene, or full-screen.
  • Particles: snow, rain, sparks.
  • Canvas: anything you draw with your own code.

show scene doesn’t take these away: hide each with its own hide statement.