我有一个2人,iOS回合制游戏,使用游戏中心和GKTurnbasedMatch.
有没有办法在比赛结束后以编程方式重新匹配对手?
我想让玩家一键式访问彼此开始新的比赛.
如果没有一键式方法,有哪些潜在的替代方案?
小智 4
事实上,游戏中心似乎忽略了完整的编程解决方案。毫无疑问,这是一种痛苦。在 @selector(doRematchTap)... 或其他等效项中尝试以下操作:
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:^{
}];
Run Code Online (Sandbox Code Playgroud)
重要的是要注意 showExistingMatches = NO,这将使视图控制器直接跳转到匹配模式,并预先选择正确的用户(看起来),并且不显示用户的现有匹配。
| 归档时间: |
|
| 查看次数: |
1000 次 |
| 最近记录: |