开发者

trouble negotiating a 2 player match in game kit

开发者 https://www.devze.com 2023-02-21 11:01 出处:网络
I am getting some behavior I can\'t decode f开发者_如何学Gorom GameKit. sometimes the player who has done the inviting gets stuck in a \'waiting...\' loop, and is unable to close the deal on his invi

I am getting some behavior I can't decode f开发者_如何学Gorom GameKit.

sometimes the player who has done the inviting gets stuck in a 'waiting...' loop, and is unable to close the deal on his invitation.

I believe it has to do with multitasking and the invite handler... it seems that if the invitee's app starts from scratch, then the invitation can be properly accepted. But the mechanism of this not so transparent to me.

Any clues as to what might be missing? I've become blinded by the documentation.


Sometimes when a match between two players starts, it's possible that one player doesn't have the connected state yet. You should check if more players are expected to connect before actually starting the game. If it's over 0, instead of starting the game, wait for the player to connect, and only start the game when that player is connected.

So the code would look something like this inside your the method where you are setting up the game:

if (currentMatch.expectedPlayerCount) {
    waiting = YES;
}

And you would implement this delegate method:

- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state
{
    if (state == GKPlayerStateConnected) {
        if (waiting) {
            waiting = NO;
            // start the game now
        }
    } else if (state == GKPlayerStateDisconnected) {
        // handle disconnect
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消