启动关闭云游戏
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;
}