游戏中心 - 连接多人游戏

发布于 2024-10-10 00:52:30 字数 1521 浏览 0 评论 0原文

我一直在尝试实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-10-17 00:52:30

我从未使用 GameCenter 做过任何事情,但也许我可以提供帮助。当我收到错误时

“请求的操作已
已取消”

我发现反向地理编码器中的 ,该应用程序没有时间执行请求。
您通过执行 findMatchForRequest: 收到错误,因此可能您的请求变量未设置完全,请检查。您还可以尝试将 NSLog() 放在第一行(在块中)并查看传递的变量 returnedMatcherror

I never done something with GameCenter but maybe I can help anyway. When I get the error

"The requested operation has been
cancelled"

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 a NSLog() in first line (in the block) and look in your passed variable returnedMatch and error

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文