Skip to content

getGameView ​

Get the game rendering view ​

getGameView is used to obtain the mini game engine's rendering container (UIView). This view is the sole carrier of the mini game's visual output; the app must add it to its own view hierarchy so that the user can see the game screen and interact via touch.


Method Declaration ​

objectivec
/**
 * Get the mini game rendering view.
 * @return The UIView instance that carries the game screen. Returns nil if the engine is not created or has been destroyed.
 */
- (nullable UIView *)getGameView;

Parameters ​

ParameterTypeRequiredDescription
None--This method takes no parameters.

Runtime Behavior ​

  1. View ownership: This view is created and held internally by the engine. Calling this method only returns a reference to that instance.
  2. Lifecycle binding: The view's lifecycle is bound to the gameHandle. Once destroy is executed, the view is destroyed and subsequent calls return nil.
  3. Rendered content: The view internally wraps a Metal or OpenGL Layer, responsible for presenting all graphical content output by the game script.

Example ​

The mount operation is usually performed on the main thread after observing the SUD_RT_GAME_STATE_WAITING state:

objectivec
#pragma mark - SUDRTGameStateChangeListener

- (void)onStateChangedFrom:(int)fromState to:(int)toState {
    if (toState == SUD_RT_GAME_STATE_WAITING) {
        // UI must be operated on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            UIView *gameView = [self.gameHandle getGameView];
            if (gameView) {
                // Set the layout and add it to the current ViewController's View
                gameView.frame = self.view.bounds;
                gameView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
                [self.view addSubview:gameView];
                
                NSLog(@"Game view mounted successfully");
            }
        });
    }
}

Notes ​

  • Thread safety: Although getGameView itself can be called across threads, the returned UIView and subsequent addSubview: operations must be performed on the main thread.
  • Repeated mounting: Multiple calls to getGameView return the same instance. When switching pages or toggling full screen, handle the view's parent-child relationship carefully.
  • Layer management: If the app needs to overlay native UI on top of the game screen (such as chat bubbles or a close button), make sure those native components sit above gameView.
  • Resizing: If the container view's size changes (such as on orientation switch), synchronously update the gameView's frame to trigger the engine's internal render resolution adaptation.