Skip to content

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 ​

ParameterTypeRequiredDescription
None--This method takes no parameters; it only performs low-level environment initialization.

Runtime Behavior ​

  1. Resource allocation: The SDK starts the underlying C++ core engine and allocates a dedicated Rendering Surface for the mini game.
  2. Environment loading: Initializes the JavaScriptCore virtual machine and loads the mini game's Base Lib and runtime environment scripts.
  3. State transition: After success, the state transitions from SUD_RT_GAME_STATE_UNAVAILABLE (0) to SUD_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: create only 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 create and subsequent UI operations (such as getGameView) both be initiated on the main thread.
  • Memory management: Once create is 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 call destroy to release resources.
  • Repeated calls: If the current instance is already in WAITING or a higher state, repeated calls to create will be automatically ignored by the SDK.