Add Actions
A scene runs its actions from top to bottom. Pass the complete action list to scene.action() once.
import { Character, Scene } from "narraleaf-react";
const kitchen = new Scene("kitchen", {
background: "/backgrounds/kitchen.webp",
});
const street = new Scene("street", {
background: "/backgrounds/street.webp",
});
const alice = new Character("Alice");
kitchen.action([
alice.say("Breakfast is ready."),
kitchen.jumpTo(street),
]);Most methods on story elements return actions: character.say(), image.show(), sound.play(), and scene.jumpTo() are common examples. Plain strings are also accepted and are rendered as narrator lines.
kitchen.action([
"The room is quiet.",
alice.say("Let's go."),
]);Use the callback form when you want a short local name for the current scene:
import { Control } from "narraleaf-react";
const room = new Scene("room").action((scene) => [
scene.setBackground("/backgrounds/room-night.webp"),
Control.sleep(500),
scene.jumpTo(street),
]);Do not call action() more than once on the same scene. Actions after jumpTo() are unreachable and will not run.
See ActionStatements for every accepted statement type.