NarraLeaf

GameState

This page is under construction.

Beta feature, subject to change.

GameState is created by a player component and can pass to other main class, such as liveGame.serialize

Public Properties

game

  • Game - The game instance

audioManager

The game's audio cache and playback manager.

// Fetch and decode a source into the audio cache without playing it.
void gameState.audioManager.preload(bgm);
  • preload(sound: Sound): Promise<void> - warm one source. Available since 0.17.0. A source that fails to load is logged as a warning and loads on first play instead, so this never rejects. Do not gate anything on the returned promise: the audio context stays locked until a user gesture satisfies the browser's autoplay policy, so it can legitimately stay pending. See Preloading.

Public Methods

preloadScene

Name the scene whose assets should be warmed, without mounting it or running any of its actions.

gameState.preloadScene(scene);   // or a Story, which uses its entry scene

Since 0.17.0 the Player registers the story's entry scene automatically — but only when there is neither a preloading scene nor a mounted scene yet, so calling this first keeps your own choice. See Preloading.

  • arg: Scene | Story - the scene to warm, or a story whose entry scene is used. Throws if a story is passed and it has no entry scene.
  • return: this

suspendAdvance

Hold the line where it is. While at least one suspension is out, a click on the stage and the advance and skip keys do nothing. Available since 0.27.0.

const release = gameState.suspendAdvance();
// ...
release();

Suspensions nest: the line resumes once every one of them has been released. The returned function is safe to call more than once.

Inside a React component, use useSuspendAdvance, which takes and releases the suspension with the component.

  • return: () => void - releases this suspension

isAdvanceSuspended

Whether anything is currently holding the line. Available since 0.27.0.

  • return: boolean

On this page