Manage Multiplayer Matches

Apple Game Frameworks and Technologies — by Tammy Coron (162 / 193)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Request a Turn-Based Match | TOC | Process Player Turns Using an Event Listener 👉

One of the neat things about Game Center and GameKit is that they include everything you need to set up and manage multiplayer games, well, almost everything — you need to supply the game data. However, before getting too deep into the game data, let’s cover the heart of turn-based matches: the GKTurnBasedMatch object.

The GKTurnBasedMatch object is what you use to implement a turn-based match. This object, which your game never creates directly, contains important information about the match. This object uses a store-and-forward approach to share your game’s match data between its match participants.

The GKTurnBasedMatch object has a few key properties:

  • participants: Holds information about the “players” participating in the game.
  • currentParticipant: This is the participant whose turn it is currently.
  • matchData: Contains the game-specific data, including the details of the match and its current state.
  • matchID: A unique string that identifies the match.

Before you get started using this class, it’ll be helpful to extend it by adding two new properties that will make it easier to know which participant is the local player.

Extending the…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.