Game onPause method

  • The onPause method subscribes to pause events in your game.

  • When the onPause callback is triggered, your game must completely pause all execution, including the game loop, sounds, music, and rendering.

  • You should not use the Page Visibility API or similar APIs for handling game pausing; only use the GameSnacks SDK methods.

  • It is recommended to save user progress when the game is paused via the onPause callback.

onPause(callback: () => void): void;

Subscribes to pause events.

Examples

GameSnacks.game.onPause(() => {
  // Display pause screen.
  engine.scene("pauseScreen").setVisible();
  engine.loop.sleep();
});

Requirements

  • Your game must pause all execution when callback is called and must resume execution only when the callback for onResume is called. This applies to all game behaviors including: the game loop, sounds, music, interactions, network calls, and rendering.
  • Your game must not use the Page Visibility API or similar APIs and must only use these GameSnacks SDK methods.
  • Your game should save user progress when callback is called.
  • Your game must clearly communicate to the user if it's paused.