您尚未登录

登录

您尚未登录

登录

推荐您使用PC浏览器访问

确定
  • 开发者中心
  • >
  • 云游戏
  • >
  • 快速入门
  • >
  • 启动关闭云游戏
  • >
  • iOS

启动关闭云游戏

1 启动游戏

1.1 申请游戏

示例代码

- (IBAction) start:(id)sender {
    NSDictionary *game = [self.gameList objectAtIndex:self.tableView.indexPathForSelectedRow.row];
    orientation = [[game objectForKey:@"portrait"] integerValue];

    NSDictionary *gameOptions = @{CloudGameOptionKeyId:[game objectForKey:@"id"],
                                  CloudGameOptionKeyOrientation:@(orientation),
                                  CloudGameOptionKeyUserId:DEMO_USERID,
                                  CloudGameOptionKeyUserToken:DEMO_USERID,
                                  CloudGameOptionKeyConfigInfo:@"config",
                                  CloudGameOptionKeyCToken:[self generateCToken:[game objectForKey:@"id"]],
                                  CloudGameOptionKeyPriority:@(0),
                                  CloudGameOptionKeyPlayingTime:@(DEMO_GAME_TIME*1000),
                                  CloudGameOptionKeyExtraId:@"",
                                  CloudGameOptionKeyArchive:@(0),
                                  CloudGameOptionKeyProtoData:@"",
                                  CloudGameOptionKeyAppChannel:[game objectForKey:@"appChannel"]
                                  };

    NSLog(@"startSDK params : %@", gameOptions);

    self.gameVC = [[HMCloudPlayer sharedCloudPlayer] prepare:gameOptions];

    if (!self.gameVC) {
        NSLog(@"startSDK Failed .");
        return;
    }
}

1.2 开始游戏

申请游戏成功后会返回一个 UIViewController,App 需通过 present 或 push 方法将其展示在界面上,并调用start方法开始游戏

- (void) cloudPlayerPrepared:(BOOL)success {
    NSLog(@"%s : %@", __FUNCTION__, success?@"YES":@"NO");

    if (success) {
         [[HMCloudPlayer sharedCloudPlayer] play];
    }
}

2 关闭云游戏

退出游戏时需要调用 stopGame

示例代码

- (void) stopGame {
    [[HMCloudPlayer sharedCloudPlayer] stop];
    self.gameVC = nil;
}
×

本篇文章对你是否有帮助?

更多建议

请输入您的建议