LiveGame
This page is under construction.
LiveGame is the main class that represents the game's current state.
Public Properties
game
The Game instance
story
The current Story instance
Public Methods
getStorable
newGame
Starts a new game
return this
deserialize
Load a saved game
After calling this method, the current game state will be lost, and the stage will trigger force reset
**Note: **Even if you change just a single line of script, the saved game might not be compatible with the new version
Example:
const savedGame = {
// ...saved game data
};
// use hook inside a component
const {game} = useGame();
// pass the saved game data to the game instance
game.getLiveGame().deserialize(savedGame);
savedGame: SavedGame
- SavedGame
serialize
Serialize the current game state
You can use this to save the game state to a file or a database
**Note: **Even if you change just a single line of script, the saved game might not be compatible with the new version
return: SavedGame
- See SavedGame`
onCharacterPrompt
Called when a character says something
fc: (event: LiveGameEvent["event:character.prompt"]) => void
- See LiveGameEvent- Returns
LiveGameEventToken
- See LiveGameEventToken
const {game} = useGame();
const [texts, setTexts] = useState<string[]>([]);
useEffect(() => {
const token = game.getLiveGame().onCharacterPrompt((event) => {
setTexts((prevTexts) => [...prevTexts, event.text]);
});
return () => {
token.cancel();
};
}, []);
return (
<div>
{/* Your Text Log */}
</div>
);
onMenuChoose
Called when a menu is completed
fc: (event: LiveGameEvent["event:menu.choose"]) => void
- See LiveGameEvent- Returns
LiveGameEventToken
- See LiveGameEventToken
capturePng
Capture the game screenshot, will only include the player element
Returns a PNG image base64-encoded data URL
const {game} = useGame();
function handleButtonClick() {
game.getLiveGame().capturePng().then((dataUrl) => {
// do something with the dataUrl
});
}
- Returns
Promise<string>
captureJpeg
Capture the game screenshot, will only include the player element
Returns compressed JPEG image data URL
- Returns
Promise<string>
captureSvg
Capture the game screenshot, will only include the player element
Returns an SVG data URL
- Returns
Promise<string>
capturePngBlob
Capture the game screenshot, will only include the player element
Returns a PNG image blob
- Returns
Promise<Blob | null>
requestFullScreen
Request full screen on Chrome/Safari/Firefox/IE/Edge/Opera, the player element will be full screen
Note: this method should be called in response to a user gesture (for example, a click event)
Safari iOS and Webview iOS aren't supported, for more information, see MDN-requestFullscreen (opens in a new tab)
options?: FullscreenOptions | undefined
- Returns
Promise<void> | void
exitFullScreen
Exit full screen
- Returns
Promise<void> | void
onPlayerEvent
Listen to the events of the player element
const {game} = useGame();
useEffect(() => {
return game.getLiveGame().onPlayerEvent("click", (event) => {
// do something
}).cancel;
}, []);
type: K
- The event typelistener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any
- The event listeneroptions?: boolean | AddEventListenerOptions
- Returns
LiveGameEventToken