pause
Pause game logic and rendering
pause is used to switch the mini game from the running state to the paused state. After calling this method, the mini game's internal frame callbacks (requestAnimationFrame), timers, and physics engine logic all stop executing, and the render loop is suspended to save system resources.
Method Declaration
objectivec
/**
* Pause the mini game.
* After success, the mini game instance enters the `WAITING` state.
* The game screen freezes on the last frame.
*/
- (void)pause;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| None | - | - | This method takes no parameters. |
Runtime Behavior
- Logic suspension: Immediately stops all JavaScript-layer business logic, including animation frame updates and async tasks.
- Render freeze: The GPU stops outputting new frames; the screen retains the frame at the moment
pausewas called. - State transition: After success, the state transitions from
SUD_RT_GAME_STATE_PLAYING (3)back toSUD_RT_GAME_STATE_WAITING (1). - Low-power mode: The engine enters a low-power state, reducing CPU and battery consumption.
Example
Typically used when the app presents a native dialog, switches to the background, or when the user actively taps a pause button:
objectivec
- (void)handleAppWillResignActive {
// 1. Check whether the game is currently in progress
if ([self.gameHandle getGameState] == SUD_RT_GAME_STATE_PLAYING) {
// 2. Pause
[self.gameHandle pause];
NSLog(@"App entered background, game paused");
}
}
// Or when the native settings button is tapped
- (void)onSettingsButtonClicked {
[self.gameHandle pause];
[self showNativeSettingsView];
}Notes
- Audio handling:
pauseusually only stops logic and rendering. It is recommended to usegetGameAudioSessionorgetMediaPlayerHandleto pause audio in sync, so the screen does not freeze while the music keeps playing. - Network connections: During pause, the mini game's long-lived network connections (such as WebSocket) usually keep their heartbeat and do not disconnect automatically.
- Resume instruction: A paused game (WAITING) must call the
playmethod to resume running. - Auto pause: In some SDK versions, removing
gameViewfrom the window may trigger an automatic pause, but explicitly callingpauseis the most reliable way to manage it.
