Monogatari Documentation
HomepageGitHubDiscordTwitter
master
master
  • Welcome
  • Getting Started
    • Step 1: Setup Your Environment
    • Step 2: Download Monogatari
    • Step 3: Get Familiarized
    • Step 4: Make Your First Visual Novel
  • Upgrading from v1.4.1
  • F.A.Q.
  • Diagnosing Errors
  • Building Blocks
    • Script & Labels
    • Characters
    • Variables & Data Storage
    • Actions
      • Life Cycle
    • Components
      • Life Cycle
      • Built-in Properties
      • Built-in Functions
  • Script Actions
    • Choices
    • Clear
    • Conditionals
    • Dialogs
    • End
    • Gallery
    • Hide Canvas
    • Hide Character
    • Hide Image
    • Hide Particles
    • Hide Video
    • Input
    • Functions
    • Jump
    • Next
    • Placeholder
    • Play Music
    • Play Sound
    • Play Voice
    • Show Canvas
    • Show Background
    • Show Character
    • Show Image
    • Show Message
    • Show Notification
    • Show Particles
    • Show Scene
    • Show Video
    • Stop Music
    • Stop Sound
    • Stop Voice
    • Vibrate
    • Wait
  • Components
    • Credits Screen
    • Quick Menu
    • Loading Screen
    • Main Screen
    • Choice Container
    • Save Slot
    • Text-Box
  • Configuration Options
    • Game Configuration
      • Asset Preloading
      • Internationalization
      • Saving
      • Skip Main Menu
      • Storage
    • Player Preferences
    • Split Files
  • Style & Design
    • Responsiveness
    • CSS Classes
    • HTML Data Attributes
    • Icons
    • Image Menus
  • Releasing Your Game
    • Chrome App
    • Desktop App
    • Mobile
    • Web
  • Advanced: Monogatari Development
    • Core Libraries
      • Artemis
      • Kayros
      • Pandora
    • Actions
    • Components
    • Translations
    • Events
  • Releases
    • v2.0.0.alpha.8
    • v2.0.0.alpha.7
    • v2.0.0.alpha.6
    • v2.0.0.alpha.5
    • v2.0.0.alpha.4
    • v2.0.0.alpha.3
Powered by GitBook
On this page
  • Description
  • Parameters
  • Properties
  • Assets Declarations
  • Supported Formats
  • Examples
  • Play Music
  • Loop Music
  • Fade In effect
  • Custom Volume
  • All Together

Was this helpful?

  1. Script Actions

Play Music

Play music media

PreviousPlaceholderNextPlay Sound

Last updated 4 years ago

Was this helpful?

Description

'play music <music_id> [with [properties]]'

The play music action let's you, as it name says, play some background music for your game. You can play as many songs as you want simultaneously.

To stop the music, check out the .

Action ID: Music

Reversible: Yes

Requires User Interaction: No

Parameters

Name

Type

Description

music_id

string

The name of the music you want to play. These assets must be declared beforehand.

properties

string

Optional. A list of comma separated properties with their respective value.

Properties

The following is a comprehensive list of the properties available for you to modify certain behaviors of the play music action.

Property Name

Type

Description

fade

string

The fade property let's you add a fade in effect to the music, it accepts a time in seconds, representing how much time you want it to take until the music reaches it's maximum volume.

volume

number

The volume property let's you define how high the music will be played.

loop

none

Make the music loop. This property does not require any value.

Assets Declarations

To play a song, you must first add the file to your assets/music/ directory and then declare it. To do so, Monogatari has an has a function that will let you declare all kinds of assets for your game.

monogatari.assets ('music', {
    '<music_id>': 'musicFileName'
});

Supported Formats

Each browser has it's own format compatibility. MP3 however is the format supported by every browser.

Examples

Play Music

The following will play the song, and once the song ends, it will simply stop.

monogatari.script ({
    'Start': [
        'play music mainTheme'
        'end'
    ]
});
monogatari.assets ('music', {
    'mainTheme': 'mainThemeSong.mp3'
});

Loop Music

monogatari.script ({
    'Start': [
        'play music mainTheme with loop'
        'end'
    ]
});
monogatari.assets ('music', {
    'mainTheme': 'mainThemeSong.mp3'
});

Fade In effect

The following will play the song, and will use a fade in effect.

monogatari.script ({
    'Start': [
        'play music mainTheme with fade 3'
        'end'
    ]
});
monogatari.assets ('music', {
    'mainTheme': 'mainThemeSong.mp3'
});

Custom Volume

The following will set the volume of this song to 73%.

monogatari.script ({
    'Start': [
        'play music mainTheme with volume 73'
        'end'
    ]
});
monogatari.assets ('music', {
    'mainTheme': 'mainThemeSong.mp3'
});

Please note however, that the user's preferences regarding volumes are always respected, which means that this percentage is taken from the current player preferences, meaning that if the player has set the volume to 50%, the actual volume value for the song will be the result of:

50∗0.73=36.550 * 0.73 = 36.5%50∗0.73=36.5

All Together

Of course, you can combine all of this properties, and remember the order doesn't really matter, you can write the properties on the order that feels more natural to you.

monogatari.script ({
    'Start': [
        'play music mainTheme with volume 100 loop fade 20'
        'end'
    ]
});
monogatari.assets ('music', {
    'mainTheme': 'mainThemeSong.mp3'
}

If you wish to use other formats, you can check a to discover what browsers will be able to play it.

The following will play the song, and once the song ends, it will start over on an infinite loop until it is stopped using the .

Stop Music documentation
compatibility table
Stop Music Action