Lifecycle Events
The Lifecycle module offers a comprehensive suite of events that developers can utilize to manage game flow, from initialization to conclusion. These events are instrumental in creating a seamless and interactive gaming experience.
For a detailed exploration of the API, visit the game lifecycle documentation.
Engaging with the game lifecycle involves handling events such as:
-
The game becoming ready to play;
-
The start of the game;
-
Score changes and updates;
-
The end of the game session.
Supported Events
Arkadium's Game SDK supports a variety of lifecycle events, each serving a distinct purpose in the game's lifecycle:
onTestReady - Indicates the game is loaded and ready for interaction.
Always make sure to call the onTestReady()
event once the game is ready to be shown to the user.
Failing to do so will prevent the Game Loading overlay from being removed on the Arena, and the user will not be able to interact with the game.
onGameStart - Marks the beginning of gameplay.
onChangeScore - Triggers before the game concludes to update scores.
onGameEnd - Signifies the end of the game session.
Properly handling these events is crucial for a fluid game experience and for maintaining game state integrity.
Events Overview
Game Ready (onTestReady)
This event signals that the game has fully loaded and is ready for play. It is ideal for initializing game setups or displaying ready cues to the player.
await sdk.lifecycle.onTestReady();
Game Start (onGameStart)
Triggered at the commencement of the game, it denotes the start of the player's interaction with the game environment.
await sdk.lifecycle.onGameStart();
Score Change (onChangeScore)
Occurs before the game's conclusion, allowing for the update and display of the player's score or other metrics.
await sdk.lifecycle.onChangeScore(1234);
Game End (onGameEnd)
Marks the completion of the game, facilitating the execution of wrap-up operations such as saving progress, showing results, or transitioning to end screens.
await sdk.lifecycle.onGameEnd();
Registering Event Callback
In some flows, the Arena might need to control the game flow by pausing and resuming the game. The game will need to implement it's own pause/resume logic and register it as an event callback. There are 2 events to which the game will need to register callbacks: GAME_PAUSE and GAME_RESUME. Below there are examples on how to register these callbacks.
sdk.lifecycle.registerEventCallback(sdk.lifecycle.LifecycleEvent.GAME_PAUSE, () => {
// logic to PAUSE game goes here
});
sdk.lifecycle.registerEventCallback(sdk.lifecycle.LifecycleEvent.GAME_RESUME, () => {
// logic to RESUME game goes here
});
Conclusion
Leveraging the Game Lifecycle events effectively ensures that players enjoy a coherent and engaging gaming experience, from start to finish. These events allow for precise control over the game flow, enhancing interactivity and player satisfaction.