私のゲームには、ユーザーが選択できる 3 つの異なるレベルがあります。プレイヤーが選択したレベルを GKMatchRequest の playerGroup 属性に保存しました。試合が行われた後、GKTurnBasedMatch から playerGroup を取得するにはどうすればよいですか? または、試合がどのゲーム レベルであるかを追跡する別の方法はありますか?
2 に答える
1
GKMatchRequestを作成したら、findMatchForRequestを呼び出す必要があります。findMatchForRequestの完了ハンドラーで、ゲームのレベルを新しい一致のmatchDataプロパティに格納できます。
于 2012-09-24T08:21:52.340 に答える
1
自動対戦/招待 UI を表示するために GKTurnBasedMatchmakerViewController を使用します。GKMatchRequest を作成するとき、次のように ObjC に関連付けられた playerGroup 値 (NSNumber にパック) を GKTBMVC に追加します。
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.playerGroup = somePlayerGroup;
GKTurnBasedMatchmakerViewController *mmvc = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
objc_setAssociatedObject(mmvc,
&kPlayerGroupKey,
[NSNumber numberWithInteger:request.playerGroup],
OBJC_ASSOCIATION_RETAIN);
[myViewController presentViewController:mmvc
animated:YES
completion:nil];
次に、turnBasedMatchmakerViewController:didFindMatch:
デリゲート メソッドでplayerGroup
値を読み取り、設定または参加する必要がある一致の種類を確認します。
- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)mmvc didFindMatch:(GKTurnBasedMatch *)match
{
[myViewController dismissViewControllerAnimated:YES
completion:^{
NSNumber *n = objc_getAssociatedObject(mmvc, &kPlayerGroupKey);
NSInteger playerGroup = [n integerValue];
[self switchToMatch:match matchKind:playerGroup];
}];
}
もちろん、新しいマッチを作成するときに保存することもできますがplayerGroup
、match.matchData
マッチメイキング ビュー コントローラで渡す方が便利な場合もあります。
于 2013-07-22T13:08:29.933 に答える