create
Initialize the mini game runtime environment
create is the first core instruction that starts the mini game lifecycle. It builds the base environment required to run the mini game from the "unavailable" state, including allocating memory, initializing the rendering engine (Metal/GPU), and starting the JavaScript virtual machine (JSC). At this point the engine is in a generic initialized state and has not yet bound to any specific game business.
Method Declaration
objectivec
/**
* Initialize the mini game runtime environment.
* After success, the mini game instance enters the `WAITING` state.
* This stage only initializes the engine's base capabilities and does not depend on any specific game configuration.
*/
- (void)create;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| None | - | - | This method takes no parameters; it only performs low-level environment initialization. |
Runtime Behavior
- Resource allocation: The SDK starts the underlying C++ core engine and allocates a dedicated Rendering Surface for the mini game.
- Environment loading: Initializes the JavaScriptCore virtual machine and loads the mini game's Base Lib and runtime environment scripts.
- State transition: After success, the state transitions from
SUD_RT_GAME_STATE_UNAVAILABLE (0)toSUD_RT_GAME_STATE_WAITING (1).
Example
objectivec
// 1. Register the state listener
[self.gameHandle setGameStateListener:self];
// 2. Trigger the create logic (no gameId required at this point)
[self.gameHandle create];
#pragma mark - SUDRTGameStateChangeListener callback
- (void)onStateChangedFrom:(int)fromState to:(int)toState {
if (toState == SUD_RT_GAME_STATE_WAITING) {
NSLog(@"Engine environment ready, entering WAITING state");
dispatch_async(dispatch_get_main_queue(), ^{
// 3. Get the View and add it to the container for display
UIView *gameView = [self.gameHandle getGameView];
if (gameView) {
gameView.frame = self.view.bounds;
[self.view addSubview:gameView];
}
// 4. Next steps: set options and start the specific game
// [self.gameHandle setGameStartOptions:gameId options:options];
// [self.gameHandle start:onShowMsg];
});
}
}Notes
- Independence:
createonly relates to the engine lifecycle; the engine has not yet loaded any specific game script at this point. - Thread safety: Although the initialization involves background threads, it is recommended that calling
createand subsequent UI operations (such asgetGameView) both be initiated on the main thread. - Memory management: Once
createis called, the engine occupies video memory and system memory. If the user exits after the environment is created without entering the game, be sure to calldestroyto release resources. - Repeated calls: If the current instance is already in
WAITINGor a higher state, repeated calls tocreatewill be automatically ignored by the SDK.
