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.
http://www.2shared.com/file/fPOCLlg5/gkTest.html
Hi
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.
Could someone please explain the code samples in the Official Apple docs here please: http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/MatchesandVoice/MatchesandVoice.html#//apple_ref/doc/uid/TP40008304-CH10-SW4
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:
- (void) sendPosition
{
NSError *error;
PositionPacket msg;
msg.messageKind = PositionMessage;
msg.x = currentPosition.x;
msg.y = currentPosition.y;
NSData *packet = [NSData dataWithBytes:&msg length:sizeof(PositionPacket)];
[match sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error:&error];
if (error != nil)
{
// handle the error
}
}
And receiving:
- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID
{
Packet *p = (Packet*)[data bytes];
if (p.messageKind == PositionMessage)
// handle a position message.
}
My big question about this code form the official docs is:
Where does PositionPacket
/Packet
come from?
And assuming when you want to send/receive data you call them like so:
[self sendPosition];
or
[self match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID];
What do I enter as the match, data and playerID?
E.g. I have an int named 'score' but is there not a special key I need to use something?
match
is this just a new GKMatch I can declare or does it need to be from a specific place? – Hypercritical