Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-27-2011, 07:00 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
Curtis is on a distinguished road
Default 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.
Curtis is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 427
7 members and 420 guests
chemistry, Emy, hussain1982, mistergreen2011, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,922
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0