I am working on building a game where a user is able to build their own map to explore. Using GameKit and Game Center is it possible to challenge another user to play that map that was just created?

If so, how does this work so that the other user can see the graphics, data, etc that was created within another users game instance?

有帮助吗?

解决方案

It would depend entirely on how your game is designed. GameCenter doesn't really care what sort of data you are sending in a match, as long as it adheres to the limits Game Center Places on messages.

The common factor is that you need to find a way to serialize your custom level into a format that can be sent over Game Center, then write deserialization methods to get the data into the map's format. If your maps are persistent, you can probably just send the file (unless you are using a very inefficient representation) and then use your regular methods for making a map out of the file.

For simplicity, lets say that you're making a turn-based game with a Minecraft-like board, so the only thing that you can edit is the height of each block. You might send a special turn with the JSON-serialized equivalent of

 NSArray* board = //Array of arrays of NSNumbers with the heights of each block. 
 NSArray* turn = @[@"This is the turn that sends the board", board];

 //serialize this into a NSData with JSON then send it with endTurnWithMatchData:

Then in your receivedTurnEventForMatch: method, you test for the special string in index zero that turn, or just expect it to be the first turn, and then use it to create the board, and programmatically end your current turn with no action if it is the other player's turn, or let the player receiving the custom map make his first turn.

For more ambitious custom content like images you would have to get the maximum size turn you can currently send and then break up the images into chunks to send.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top