Documentation
Scene

Scene

Scene contains multiple actions that can be performed on the scene.

For example, you can add a Character Action to the scene

import { Scene } from 'narraleaf-react';
 
const scene = new Scene("scene 1");
const character1 = new Character("character 1");
 
scene.action([
    character1
        .say("Hello World")
        .say("How are you?"),
]);

Public Method

constructor

  • name: string - Name of the scene
  • config?: DeepPartial<SceneConfig> - SceneConfig

action

Add actions to the scene. Do not call this method more than once.

Overload 1 of 2

  • actions: (ChainableAction | ChainableAction[])[] - Actions to be executed, see ChainedActions

Overload 2 of 2

This overload let you pass a function that receives the scene instance and returns the actions to be executed.

In some cases, you may want to make a shortcut to the scene instance

story.entry(
    new Scene("scene 1").action(scene => [
        scene
            .setBackground(background)
            .sleep(1000),
    ])
);
  • actions: ((scene: Scene) => ChainedAction[]) - Actions to be executed, see ChainedActions

Chainable Method

activate

This is only used when auto activation is not working

deactivate

This is only used when auto deactivation is not working

setBackground

Set background of the scene. If the transition is provided, the background will be changed with the transition effect.

applyTransform

Apply a transform to the background. Usually used for shaking or zooming effect.

jumpTo

Jump to another scene. If the transition is provided, the scene will be changed with the transition effect.

Note: The current scene will be disposed after jumping to another scene. The rest of the actions will not be executed.

  • arg0: Scene - The Scene instance you want to jump to
  • config: Partial<JumpConfig> - Jump Config

sleep

Sleep for a duration before executing the next action.

Overload 1 of 3

  • ms: number - Duration in milliseconds

Overload 2 of 3

  • promise: Promise<any> - Promise to wait for

Overload 3 of 3

  • awaitable: Awaitable<any, any> - unresolved Awaitable

setBackgroundMusic

Set background music of the scene.

  • sound: Sound - Sound instance
  • fade?: number - If set, the fade-out effect will be applied to the previous music, and the fade-in effect will be applied to the current music, with a duration in milliseconds