Skip to content

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 ​

ParameterTypeRequiredDescription
None--This method takes no parameters.

Runtime Behavior ​

  1. Logic suspension: Immediately stops all JavaScript-layer business logic, including animation frame updates and async tasks.
  2. Render freeze: The GPU stops outputting new frames; the screen retains the frame at the moment pause was called.
  3. State transition: After success, the state transitions from SUD_RT_GAME_STATE_PLAYING (3) back to SUD_RT_GAME_STATE_WAITING (1).
  4. 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: pause usually only stops logic and rendering. It is recommended to use getGameAudioSession or getMediaPlayerHandle to 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 play method to resume running.
  • Auto pause: In some SDK versions, removing gameView from the window may trigger an automatic pause, but explicitly calling pause is the most reliable way to manage it.