Skip to content

play ​

Resume game logic and rendering ​

play is used to switch the mini game from the paused or ready state to the active running state. After calling this method, the mini game's internal frame callbacks (requestAnimationFrame), physics engine, timers, and user interaction responses are fully activated, and the screen starts updating in real time.


Method Declaration ​

objectivec
/**
 * Start or resume the mini game.
 * After success, the mini game instance enters the `PLAYING` state.
 * Game logic is fully enabled, and touch events start being received.
 */
- (void)play;

Parameters ​

ParameterTypeRequiredDescription
None--This method takes no parameters.

Runtime Behavior ​

  1. Engine activation: Resumes the Render Loop, driving the GPU to continuously output new frames.
  2. Logic unfreeze: The JavaScript-layer requestAnimationFrame starts triggering normally, resuming all previously paused scheduled tasks.
  3. Interaction enabled: The mini game container view (GameView) starts receiving and handling the user's native touch events (Touches).
  4. State transition: After success, the state transitions from SUD_RT_GAME_STATE_WAITING (1) or SUD_RT_GAME_STATE_RUNNING (2) to SUD_RT_GAME_STATE_PLAYING (3).

Example ​

Typically used when returning to the game from native UI, when the app returns to the foreground from the background, or when the game officially starts after loading:

objectivec
- (void)handleAppDidBecomeActive {
    // 1. Check whether the state is WAITING
    if ([self.gameHandle getGameState] == SUD_RT_GAME_STATE_WAITING) {
        // 2. Resume the game
        [self.gameHandle play];
        NSLog(@"App returned to foreground, game resumed");
    }
}

// After observing that the game script started successfully (RUNNING)
- (void)onStateChangedFrom:(int)fromState to:(int)toState {
    if (toState == SUD_RT_GAME_STATE_RUNNING) {
        // 3. The script is ready; immediately enter playing mode
        [self.gameHandle play];
    }
}

Notes ​

  • Prerequisite: Before calling play, make sure create has been executed. Calling it in the UNAVAILABLE state has no effect.
  • Audio sync: play mainly resumes rendering and logic. If audio was previously paused manually (via AudioSession), it is recommended to resume sound playback here in sync.
  • Performance cost: After entering the PLAYING state, CPU and GPU load increase significantly.
  • Interaction prerequisite: Only after entering the PLAYING state will taps on in-game buttons produce feedback.