Scene
This page is under construction.
Beta feature, subject to change.
This class extends Displayble
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 Properties
local
scene.local is a Persistent instance that is local to the scene.
It is used to store the temporary data that is only available in the scene.
Local data doesn't need to be registered or initialised, but it is 'undefined' before it is used.
Data in local will be discarded when the scene is exited.
scene.action([
new Menu("Which coffee do you want?")
.choose("Latte", [
scene.local.set("coffee", "latte"),
])
.choose("Cappuccino", [
scene.local.set("coffee", "cappuccino"),
]),
character1.say`You chose ${scene.local.get("coffee")} coffee`,
]);background
This property is used to access the background Image instance of the scene.
scene.background
.char("background.png", new Dissolve(1000, "linear"))backgroundLayer
This property is used to access the background layer of the scene.
This layer contains the background image of the scene.
scene.backgroundLayer.opacity(0.5, 1000, "linear")displayableLayer
This property is used to access the displayable layer of the scene.
This layer contains all the displayables that don't belong to any specific layer.
scene.displayableLayer.opacity(0.5, 1000, "linear")Public Method
constructor
name: string- Name of the sceneconfig?: Partial<ISceneUserConfig>- ISceneUserConfig
action
Add actions to the scene. Do not call this method more than once.
Overload 1 of 2
actions: ActionStatements- Actions to be executed, see ActionStatements
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) => ActionStatements)- Actions to be executed, see ActionStatements- Returns
this
preloadImage
Manually register image sources
src: string | string[]- The URL of the image or an array of URLs- Returns
this
Chainable Method
setBackground
Alias of scene.background.char.
Set background of the scene. If the transition is provided, the background will be changed with the transition effect.
scene.action([
scene.setBackground("background.png")
// is equivalent to
scene.background.char("background.png")
]);background: Color | ImageSrc- See Color or ImageSrctransition?: ImageTransition- For ImageTransition, see Transition
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.
scene: Scene | string- The Scene instance or the name of the scene to jump toconfig: Partial<JumpConfig>- Jump Config
setBackgroundMusic
Set background music of the scene.
sound: Sound- Sound instancefade?: 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
nvl
Create an NVL (Novel) mode block for displaying accumulated dialog. In NVL mode, dialogs are stacked on screen rather than replacing each other, similar to classic visual novel narration.
Overload 1: actions only
actions: ActionStatements | ((nvl: NVLToken) => ActionStatements)- Actions to execute within NVL mode, or a callback that receives an NVLToken for manual show/hide/end control- Returns
ChainableAction
scene.action([
scene.nvl([
character.say("First line"),
character.say("Second line"),
character.say("Third line"),
]),
]);Overload 2: options + actions
options: Partial<TransformDefinitions.CommonTransformProps>- Transition options for showing and hiding the NVL layer (e.g.{ duration: 500 }). See CommonTransformPropsactions: ActionStatements | ((nvl: NVLToken) => ActionStatements)- Same as Overload 1- Returns
ChainableAction
scene.action([
scene.nvl({ duration: 300 }, [
character.say("Line 1"),
character.say("Line 2"),
]),
]);Callback form with NVLToken
When you pass a callback (nvl) => [...], you can use nvl.show(), nvl.hide(), and nvl.end() to control the NVL layer explicitly:
scene.action([
scene.nvl(nvl => [
character.say("Line 1"),
character.say("Line 2"),
nvl.hide({ duration: 500 }),
Control.waitForClick(),
nvl.show({ duration: 500 }),
character.say("Line 3"),
nvl.end(),
]),
]);NVL Token methods
When using the callback form scene.nvl(nvl => [...]), the nvl argument is an NVLToken with these chainable methods:
| Method | Description |
|---|---|
nvl.show(options?) | Show the NVL layer with optional transition (e.g. { duration: 500 }). See CommonTransformProps. |
nvl.hide(options?) | Hide the NVL layer with optional transition. Does not exit NVL mode or clear dialogs. |
nvl.end() | Force exit NVL mode immediately. Clears all accumulated dialogs and hides the NVL layer. |