Show Character Layer

Control individual layers of a character sprite

[!WARNING] This feature is currently Experimental. Syntax and behavior may change in future versions. Requires ExperimentalFeatures to be enabled in settings.

Description

The Character Layer actions allow you to manipulate specific parts (layers) of a composite character sprite independently. This is useful for paper-doll systems where you want to change expressions, outfits, or accessories without replacing the entire character image.

Actions

Action
ID
Description

Show Layer

Show::Character::Layer

Display or change a specific layer

Hide Layer

Hide::Character::Layer

Remove a specific layer

Reversible: Yes

Requires User Interaction: No

Character Setup

To use layers, your character definition must include:

  1. layers - An array defining the layer order (bottom to top, determines z-index)

  2. layer_assets - An object mapping layer names to their available sprites

monogatari.characters({
    'y': {
        name: 'Yui',
        directory: 'yui',
        // Define layer order (bottom to top)
        layers: ['base', 'clothes', 'face', 'accessories'],
        // Define available sprites for each layer
        layer_assets: {
            base: {
                body: 'base_body.png'
            },
            clothes: {
                uniform: 'clothes_uniform.png',
                casual: 'clothes_casual.png',
                swimsuit: 'clothes_swimsuit.png'
            },
            face: {
                neutral: 'face_neutral.png',
                happy: 'face_happy.png',
                sad: 'face_sad.png',
                angry: 'face_angry.png'
            },
            accessories: {
                glasses: 'acc_glasses.png',
                hat: 'acc_hat.png'
            }
        },
        // Standard sprites can still be used
        sprites: {
            normal: 'normal.png' // Fallback non-layered sprite
        }
    }
});

Layer Order

The layers array determines the z-index of each layer. Layers listed first appear behind layers listed later:

Show Layer

Displays a specific sprite on a specific layer for a character.

Properties

Name
Description

duration

Sets animation-duration CSS property. Format: duration <time>

transition

Sets transition-duration CSS property. Format: transition <time>

end-<animation>

Animation to play when this layer is changed

Prerequisites

The parent character must be shown first using show character before adding layers:

Examples

Set Yui's face to happy:

Change clothes with animation:

Add glasses with a fade effect:

Prepare exit animation for a layer:

Hide Layer

Removes a specific layer from a displayed character.

Properties

Name
Description

duration

Sets animation-duration CSS property. Format: duration <time>

Examples

Remove Yui's glasses:

Remove glasses with animation:

Remove with custom duration:

Complete Example

State Management

State

Character layers are tracked in the engine state:

History

Layer changes are recorded in history for rollback support:

Error Handling

The actions will show errors if:

  1. Character not found: The character ID doesn't exist

  2. Layer not shown: Attempting to hide a layer that isn't displayed

  3. Parent not shown: Attempting to add a layer when the character isn't displayed

CSS Styling

Layer images are rendered as <img> elements inside a wrapper:

Last updated

Was this helpful?