How is GKTurnBasedMatchmaker used?

风流意气都作罢 提交于 2020-02-08 07:54:09

问题


I'm trying to create a simple turn based 2 player game, but am struggling to understand how to use GKTurnBasedMatchmaker

Here's the steps I have so far:

  • Authenticate Local Player
  • Make my view controller the GKTurnbasedMatchmakerViewControllerDelegate
  • Present the matchmaking view controller like so:

    self.match.minPlayers = 2;
    self.match.maxPlayers = 2;
    self.match.defaultNumberOfPlayers = 2;
    
    
    let mmVC = GKTurnBasedMatchmakerViewController(matchRequest: match);
    mmVC.turnBasedMatchmakerDelegate = self;
    self.view?.window?.rootViewController?.present(mmVC, animated: true, completion: nil);
    

I now have no idea what to do after this.

How can I tell if the matchmakerViewController successfully found a match and I should transition to the game?

The didFindMatch callback seemed like the obvious solution, but it's deprecated


回答1:


I am also having trouble with GKTurnBasedMatch. But I may be able to help you take a few steps forward.

First look at some of the other answered questions related to this for problems you may have down the road. Apparently the whole GKLocalPlayerListener protocol is giving alot of people trouble: Another question about GTTurnBasedMatch

Anyways:

The GKTurnbasedMatchmakerViewControllerDelegate protocol now only has two methods associated with it. There is one for canceling the VC and one to handle an error.

If looks like Apple may have chosen to not to let GKTurnbasedMatchmakerViewControllerDelegate handle any of the actual matchmaking methods; they instead gave those responsibilities to the GKTurnBasedEventListener protocol (under GKLocalPlayerListener).

So after you do what you have done above make sure to do the following:

  1. Make you main VC adhere to the GKLocalPlayerListener protocol.
  2. Register your VC via [[GKLocalPlayer localPlayer] registerListener:self];
  3. Implement - (void)player:(GKPlayer *)player receivedTurnEventForMatch:(GKTurnBasedMatch *)match didBecomeActive:(BOOL)didBecomeActive, from the GKLocalPlayerListener protocol

When you start a new game this function should fire.

Unfortunately, I am still trying to overcome other obstacles I have hit with GK, good luck to you.



来源:https://stackoverflow.com/questions/47645092/how-is-gkturnbasedmatchmaker-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!