Music and Sound
A bell rings when the story starts, and quiet music plays by the palace until the ending. On this page you add both.
NOTE
Music, sounds and voices play with the game opened from its file and served. Opened from its file, they play without the audio effects a play statement can add, which this page doesn’t use. What works opened from a file has the details.
Declare the audio files
Like backgrounds, music and sounds are assets: you give each file a name before the script uses it. The tutorial assets you copied earlier put theme.mp3 in assets/music/ and bell.mp3 in assets/sounds/.
In js/script.js, find the lists of music and sounds, above the backgrounds, and fill them in:
// Define the music used in the game.
monogatari.assets('music', {
'theme': 'theme.mp3',
});// Define the sounds used in the game.
monogatari.assets('sounds', {
'bell': 'bell.mp3',
});The difference between the two: music is meant to play for a while, often over and over, and sounds are short effects that play once. Monogatari keeps them apart, and players set the volume of each on the Settings screen.
Play them in the script
Add four statements to the script you have: 'play sound bell' and 'play music theme with loop' at the start, and 'stop music with fade 3' before each ending’s centered line. The whole script, with them:
monogatari.script({
'Start': [
'show scene #2b2340',
'play sound bell',
'The bell rings at the end of the drawing class.',
'show scene afternoon with fadeIn',
'play music theme with loop',
'Everyone hurries off, and soon the path to the Palacio de Bellas Artes is quiet.',
'Someone left a sketchbook on the low wall by the path.',
'show character y happy with fadeIn',
"y Oh, you're still here too?",
'show character y worried',
'y Hey, look. Someone forgot their sketchbook.',
{
'Choice': {
'Dialog': 'y What should we do with it?',
'Read': {
'Text': 'Read the first page',
'Do': 'jump ReadIt',
},
'Return': {
'Text': 'Find its owner',
'Do': 'jump ReturnIt',
},
},
},
],
'ReadIt': [
'show character y smiling',
'y Only the first page. Nobody will know.',
'The first page is a drawing of the palace, with two people on the path in front of it.',
'show character y happy at right',
'show character m worried at left with fadeIn',
'm That... is my sketchbook.',
'show character y worried at right',
'y Sorry, Mio. We should have asked first.',
'show character m happy at left',
"m It's fine. You two are in the drawing anyway.",
'stop music with fade 3',
'centered Ending 1 of 2: The Drawing',
'end',
],
'ReturnIt': [
'y It says Mio on the cover. She always stays to draw the palace when the lamps come on.',
'show scene night with fadeIn',
'Night falls over the palace.',
'show scene nightLight with fadeIn',
'One by one, the lamps light up.',
'show character y happy at right with fadeIn',
'show character m happy at left with fadeIn',
'y Mio! We found your sketchbook.',
'show character m smiling at left',
'm My sketchbook! I looked everywhere for it.',
'show character m happy at left',
'm Thank you. Do you want to see what I was drawing?',
'stop music with fade 3',
'centered Ending 2 of 2: The Lamps',
'end',
],
});What the new statements do:
'play sound bell'plays the sound calledbellonce.'play music theme with loop'starts the music calledtheme.with loopmakes it start over each time it ends, so it plays until something stops it.'stop music with fade 3'lowers the music over three seconds until it’s silent. The game waits for those three seconds, then shows the ending’s title. Withoutwith fade 3, the music stops at once.
The two play statements don’t wait for the player: the game goes straight on to the next statement while the sound plays.
Hear it
Reload the game and click Start. The bell rings over the dark screen, and the music starts when the palace appears. At each ending, the music fades out, and the ending’s title shows once it’s silent.
When you hear nothing
A misspelled name, or a file missing from assets/music/ or assets/sounds/, doesn’t stop the story: the game goes on in silence, and an error dialog names the file it couldn’t load. When something goes wrong explains how to find it.
Music on the main menu
The 'MainScreenMusic' setting in js/options.js plays a music on the main menu. Give it the name of a music you declared:
// Music for the Main Menu.
'MainScreenMusic': 'theme',Browsers don’t let a page play sound before the player has clicked on it, so the first time, the main menu may show Click here to allow audio playback. at the top; one click and the music starts.
Next
The player’s name: Yui asks who you are.