Note that there are some explanatory texts on larger screens.

plurals
  1. POGame Center - Sending and receiving data
    primarykey
    data
    text
    <p>EDIT: I have made a clean, new project, but still can't get it working. Please download it, there is a little code to look at and probably easy for a professional or anyone remotely experience to see whats I am doing wrong. Just trying to send that integer.</p> <p><a href="http://www.2shared.com/file/fPOCLlg5/gkTest.html" rel="noreferrer">http://www.2shared.com/file/fPOCLlg5/gkTest.html</a></p> <p>Hi</p> <p>I am trying to implement Game Center multiplayer in my iphone game and having trouble understanding the samples I have at hand in the Apple Docs and from third parties concerning sending and receiving data.</p> <p>Could someone please explain the code samples in the Official Apple docs here please: <a href="http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/MatchesandVoice/MatchesandVoice.html#//apple_ref/doc/uid/TP40008304-CH10-SW4" rel="noreferrer">http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/MatchesandVoice/MatchesandVoice.html#//apple_ref/doc/uid/TP40008304-CH10-SW4</a></p> <p>Or help me figure out this sample code I was supplied with. Its a prebuilt class, made to handle all the game center tasks and a sample from it for sending and receiving data would be this:</p> <pre><code>- (void) sendPosition { NSError *error; PositionPacket msg; msg.messageKind = PositionMessage; msg.x = currentPosition.x; msg.y = currentPosition.y; NSData *packet = [NSData dataWithBytes:&amp;msg length:sizeof(PositionPacket)]; [match sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error:&amp;error]; if (error != nil) { // handle the error } } </code></pre> <p>And receiving:</p> <pre><code>- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID { Packet *p = (Packet*)[data bytes]; if (p.messageKind == PositionMessage) // handle a position message. } </code></pre> <p>My big question about this code form the official docs is:</p> <p>Where does <code>PositionPacket</code>/<code>Packet</code> come from? And assuming when you want to send/receive data you call them like so:</p> <pre><code>[self sendPosition]; </code></pre> <p>or</p> <pre><code>[self match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID]; </code></pre> <p>What do I enter as the match, data and playerID?</p> <p>E.g. I have an int named 'score' but is there not a special key I need to use something?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload