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
| Parameter | Type | Required | Description |
|---|---|---|---|
| None | - | - | This method takes no parameters. |
Runtime Behavior
- Engine activation: Resumes the Render Loop, driving the GPU to continuously output new frames.
- Logic unfreeze: The JavaScript-layer
requestAnimationFramestarts triggering normally, resuming all previously paused scheduled tasks. - Interaction enabled: The mini game container view (GameView) starts receiving and handling the user's native touch events (Touches).
- State transition: After success, the state transitions from
SUD_RT_GAME_STATE_WAITING (1)orSUD_RT_GAME_STATE_RUNNING (2)toSUD_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 surecreatehas been executed. Calling it in theUNAVAILABLEstate has no effect. - Audio sync:
playmainly resumes rendering and logic. If audio was previously paused manually (viaAudioSession), it is recommended to resume sound playback here in sync. - Performance cost: After entering the
PLAYINGstate, CPU and GPU load increase significantly. - Interaction prerequisite: Only after entering the
PLAYINGstate will taps on in-game buttons produce feedback.
