Preload

Preload assets to ensure smooth playback

Description

'preload <type> <asset> [blocking]'
'preload character <id> <sprite> [blocking]'
'preload block <block_id> [blocking]'

The preload action allows you to load assets into memory before they are needed. This prevents lag or loading delays during gameplay, ensuring a smooth experience for the player.

Action ID: Preload

Reversible: No (Reverting does nothing)

Requires User Interaction: No

Parameters

Parameter
Description

type

The category of the asset (see Supported Categories below).

asset

The name/identifier of the asset to preload (as registered in monogatari.assets()).

id

When preloading a character, the character's ID.

sprite

When preloading a character, the sprite name (as defined in the character's sprites object).

block_id

When using preload block, the ID of the defined preload block to load.

blocking

(Optional) If included, the game will wait for the asset(s) to finish loading before proceeding to the next statement.

Supported Categories

Default Audio Categories (use audio loader)

  • music - Background music tracks

  • sounds or sound - Sound effects

  • voices or voice - Voice clips

Default Image Categories (use image loader)

  • scenes or scene - Scene backgrounds

  • images or image - General images

  • characters - Character sprites (uses special syntax, see examples)

Note: Singular forms (sound, voice, scene, image) are aliases for their plural counterparts.

Examples

Preload a single music track

Preload a scene (blocking)

Preload a sound effect

Preload a character sprite

Preload a predefined block of assets

Preload Blocks

Preload blocks allow you to group multiple assets together to be preloaded at once. These are defined using monogatari.action('Preload').blocks().

The default Block

The default block is a special preload block that runs automatically during the game's initial loading screen. Assets defined in the default block are:

  • Decoded and cached - Audio is decoded to AudioBuffers, images are pre-decoded for immediate display

  • Loaded before gameplay - Players see the loading progress bar while these assets load

  • Ready for instant playback - No delay when first using these assets in-game

[!TIP] Use the default block for assets needed immediately or frequently throughout the game. For chapter-specific assets, use named blocks and the preload block action.

Default Block vs. Legacy Preloading

With default Block

Without default Block (Legacy)

Only specified assets are preloaded

ALL registered assets are preloaded

Audio is decoded to AudioBuffers

Audio is only fetched to browser cache

Images are pre-decoded

Images are only fetched to browser cache

Faster first playback

May have slight delay on first use

More control over initial load time

Longer initial load with many assets

Defining Named Blocks

Named blocks are loaded on-demand using preload block <name> in your script:

Block Structure

Using Blocks in Scripts

Blocking vs Non-Blocking

By default, preload is non-blocking - the game immediately advances to the next statement while assets load in the background. This is useful for preloading assets you'll need later.

Adding the blocking keyword makes the action wait for the preload to complete before advancing. This is useful when you need the asset immediately after the preload statement.

Advanced: Custom Categories

You can register custom asset categories to use with the preload system.

Registering a Custom Category

Using Custom Categories

Once registered, custom categories work like built-in ones:

Advanced: Custom Loaders

For advanced use cases, you can register entirely custom loaders for new asset types.

Registering a Custom Loader

  • Unload - Release assets from memory when no longer needed

Last updated

Was this helpful?