ゲームセンターマルチプレイヤー用のiPhoneゲームでintを送信しようとしています。
整数が表示され、予期された値ではなく、奇数の長整数値として表示されます。
私はこれを私の.hに持っています:
typedef enum
{
kPacketTypeScore,
} EPacketTypes;
typedef struct
{
EPacketTypes type;
size_t size;
} SPacketInfo;
typedef struct
{
SPacketInfo packetInfo;
int score;
} SScorePacket;
次に.m:
データの送信:
scoreData *score = [scoreData sharedData];
SScorePacket packet;
packet.packetInfo.type = kPacketTypeScore;
packet.packetInfo.size = sizeof(SScorePacket);
packet.score = score.score;
NSData* dataToSend = [NSData dataWithBytes:&packet length:packet.packetInfo.size];
NSError *error;
[self.myMatch sendDataToAllPlayers: dataToSend withDataMode: GKMatchSendDataUnreliable error:&error];
if (error != nil)
{
// handle the error
}
受信:
SPacketInfo* packet = (SPacketInfo*)[data bytes];
switch (packet->type)
{
case kPacketTypeScore:
{
SScorePacket* scorePacket = (SScorePacket*)packet;
scoreData *score = [scoreData sharedData];
[scoreLabel setString:[NSString stringWithFormat:@"You: %d Challenger: %d", score.score, scorePacket]];
break;
}
default:
CCLOG(@"received unknown packet type %i (size: %u)", packet->type, packet->size);
break;
}
何か案は?ありがとう。