Receiving data using gamekit and storing it into an array.
Hi,
I have used this forum quite a lot over the past few months and found it really useful. So I thought I'd post something up.
I am currently working on a small game that needs to send data from it's accelerometer over a peer-to-peer connection to an iPad.
The two devices can find each other, but I am having trouble working out the right way for the iPad to receive the data. This is the concept I am using for sending the data.
UIAccelerationValue accelData[3];
accelData[0] = accelerometer.x;
accelData[1] = accelerometer.y;
accelData[2] = accelerometer.z;
- (void)sendData {
NSData *packet = [[NSData alloc] initWithBytes:accelData
length:sizeof(UIAccelerationValue)];
[gameSession sendDataToAllPeers:packet
withDataMode:GKSendDataUnreliable error:nil];
}
And this is the what I have tried for receiving the data. I want it to receive the acceleration values and store them into a new array for X, Y and Z. However I am getting an incompatible types error, I have tried casting from NSData to other data types (as well as UIAccelerationValue) such as a float or NSUInteger. But haven't had any joy.
NSData *accelData;
UIAccelerometerValue accel[3];
- (void)receiveData {
[accelData getBytes:&data length:sizeof(UIAccelerationValue)];
accel[0] = accelData[0];
accel[1] = accelData[1];
accel[2] = accelData[2];
}
I'd really appreciate some advice!
P.S. I know that I could use serialising and archiving, but it's it's a bit of an over kill for what I'm doing and this way is faster.
Thanks.
Last edited by Curtis; 03-27-2011 at 07:33 PM.
|