1

我正在尝试制作实时游戏。当玩家接受邀请时,realTimeMatchesController 将发送一个 INVITE_ACCEPTED_EVENT 事件。但 realTimeMatchesController.currentMatch 为空。并且 MATCH_MAKER_FOUND_MATCH_EVENT 事件不会调度。所以游戏就卡在了这一步。

当一个 INVITE_ACCEPTED_EVENT 被调度时,如何创建一个匹配?

这是示例代码

public function GameCenter()
 {
 if (!GameKit.isSupported)
 {
 return;
 }

_gamekit = GameKit.instance;

_gamekit.addEventListener(GameKit.LOCAL_PLAYER_AUTHENTICATED_EVENT, localPlayerAuthenticated);
 _gamekit.addEventListener(GameKit.LOCAL_PLAYER_NOT_AUTHENTICATED_EVENT, localPlayerNotAuthenticated);

_gamekit.authenticateLocalPlayer();

_gamekit.realTimeMatchesController.addEventListener(RealTimeMatchesController.INVITE_PLAYERS_EVENT, invitePlayersHandler);

_gamekit.realTimeMatchesController.addEventListener(RealTimeMatchesController.INVITE_ACCEPTED_EVENT, inviteAcceptedHandler);

_gamekit.realTimeMatchesController.init();

_gamekit.realTimeMatchesController.addEventListener(RealTimeMatchesController.MATCH_MAKER_CANCELLED_EVENT, matchMakerCancelled);

_gamekit.realTimeMatchesController.addEventListener(RealTimeMatchesController.MATCH_MAKER_FAILED_EVENT, matchMakerFailed);

_gamekit.realTimeMatchesController.addEventListener(RealTimeMatchesController.MATCH_MAKER_FOUND_MATCH_EVENT, matchMakerFoundMatch);

}

// inviter create the match
public function createMatch():void{
 _gamekit.realTimeMatchesController.startMatch(minPlayers, maxPlayers, playerGroup);
}

private function inviteAcceptedHandler(e:InviteAcceptedEvent):void
 {
 // how to start a match here?
 }

 private function matchMakerFoundMatch(e:MatchEvent):void
 {
 // save the match
  _currentMatch = e.realTimeMatch;
 _currentMatch.addEventListener(RealTimeMatch.RECEIVED_DATA_EVENT, dataReceivedHandler);
 if (_currentMatch.expectedPlayerCount == 0)
 {
  startGame();
 }
 }
4

0 回答 0