IOS Game Kit Rematch

I have an iOS-based two-player game that uses the game center and GKTurnbasedMatch.

Is there a way to programmatically replay an opponent after the match?

I would like to give players access to one button to start a new match with each other.

If there is no one-button approach, what are some potential alternatives?

+6
source share
2 answers

Indeed, it seems that the complete software solution is being ignored by Game Center. Pain, no doubt. Try the following in your @selector (doRematchTap) ... or some equivalent:

NSMutableArray *playerIds = [NSMutableArray array]; GKTurnBasedParticipant *otherPlayer = /* Get the other player some way */; GKTurnBasedParticipant *myParticipant = /* Get yourself a very similar way*/; [playerIds addObject:myParticipant.playerID]; if (otherPlayer.playerID) { [playerIds addObject:otherPlayer.playerID]; }// sanity check GKMatchRequest *request = [[GKMatchRequest alloc] init]; request.playersToInvite = playerIds; request.minPlayers = 2; request.maxPlayers = 2; GKTurnBasedMatchmakerViewController *tbmcv = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request]; tbmcv.showExistingMatches = NO; tbmcv.turnBasedMatchmakerDelegate = /* Your normal delegate for the callbacks */; [self presentViewController:tbmcv animated:YES completion:^{ }]; 

It is important to note showExistingMatches = NO, which will move the view controller directly into the matching mode with the right user (it seems) and will not display the existing user matches.

+4
source

I do not have the whole solution, but the idea for you:

Each player has a unique player identifier, which you can get if you save it after

didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID

Now you can start a programmatically new match and invite this player. He will be asked if he wants a rematch, and then you can play again.

I know that this is not a lot of code or specific advice, but perhaps there is enough information to find the rest in the GameKit Class Reference .

I wonder if you can handle it, tell me if you did good luck too!

Edit:

I searched in the links and found this:

 - (void) loadPlayerData: (NSArray *) identifiers 

I have not tried it myself, but you should get this player again if you store its identifier in an array and pass it to this function.

I hope they bring some changes to iOS6 for Game Center so that you can make your matches programmatically in your own way ...

+1
source

Source: https://habr.com/ru/post/923903/


All Articles