游戏中心 - 连接多人游戏
我一直在尝试实现 Game Center 多人游戏,并努力获得 GKMatchViewController 之外的任何东西。
我有两个视图,一个是我的主菜单,这是启动多人游戏并且玩家获取 GKMatchViewController 的地方。然后,在这背后,用户不知道,但视图更改为他们实际玩的多人游戏视图,因此当 GKMatchViewController 关闭时,他们位于游戏视图而不是菜单中。
我在这里启动多人游戏(是的,我正在使用 cocos2d):
-(void)mpGo:(id)sender{
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
withCompletionHandler:^(GKMatch *returnedMatch, NSError *error)
{
if (error) NSLog(@"match error: %@", error);
else if (returnedMatch != nil)
{
match = [returnedMatch retain];
match.delegate = self; // start!
}
}];
tempVC = [[UIViewController alloc] init];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
if (mmvc != nil)
{
mmvc.matchmakerDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
[tempVC presentModalViewController:mmvc animated: YES];
}
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[mpView node] withColor:ccWHITE]];
}
当按“立即播放”时,我收到此错误:
匹配错误:错误域=GKErrorDomain代码=2“请求的操作已被取消。” UserInfo=0x2248d0 {NSLocalizedDescription=请求的操作已取消。}
然后它就停留在“查找玩家...”视图上。
I have been trying to implement Game Center multiplayer and struggling to get anything beyond a GKMatchViewController.
I have two views, one is my main menu, this is where multiplayer is launched and the player gets the GKMatchViewController. Then behind this, the user doesn't know it but the view changes to the multiplayer view where they actually play so when the GKMatchViewController is dismissed they are in the game view rather than menu.
Here I launch multiplayer (yes I am using cocos2d):
-(void)mpGo:(id)sender{
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
withCompletionHandler:^(GKMatch *returnedMatch, NSError *error)
{
if (error) NSLog(@"match error: %@", error);
else if (returnedMatch != nil)
{
match = [returnedMatch retain];
match.delegate = self; // start!
}
}];
tempVC = [[UIViewController alloc] init];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
if (mmvc != nil)
{
mmvc.matchmakerDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
[tempVC presentModalViewController:mmvc animated: YES];
}
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[mpView node] withColor:ccWHITE]];
}
When pressing 'Play Now' I get this error:
match error: Error Domain=GKErrorDomain Code=2 "The requested operation has been cancelled." UserInfo=0x2248d0 {NSLocalizedDescription=The requested operation has been cancelled.}
Then it just stays on that 'Finding Players...' view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未使用 GameCenter 做过任何事情,但也许我可以提供帮助。当我收到错误时
我发现反向地理编码器中的 ,该应用程序没有时间执行请求。
您通过执行
findMatchForRequest:
收到错误,因此可能您的请求变量未设置完全,请检查。您还可以尝试将NSLog()
放在第一行(在块中)并查看传递的变量returnedMatch
和error
I never done something with GameCenter but maybe I can help anyway. When I get the error
in reverse geocoder I have figured out, that the app had not the time to perform the request.
You get the error by executing
findMatchForRequest:
, so maybe your request variable is not set completely, check that. You can also try to put aNSLog()
in first line (in the block) and look in your passed variablereturnedMatch
anderror