我正在尝试制作实时游戏。当玩家接受邀请时,realTimeMatchesController将调度INVITE_ACCEPTED_EVENT事件。但是realTimeMatchesController.currentMatch为null。并且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();
}
}