游戏开发中的Game Center与Cocoa Touch和cocos2d融合指南
1. Game Center数据收发
在游戏开发中,当所有玩家连接且比赛正式开始后,就可以进行数据的发送和接收操作。以下是发送和接收数据的相关代码:
-(void) sendDataToAllPlayers:(void*)data sizeInBytes:(NSUInteger)length
{
if (isGameCenterAvailable == NO)
return;
NSError* error = nil;
NSData* packet = [NSData dataWithBytes:data length:length];
[currentMatch sendDataToAllPlayers:packet
withDataMode:GKMatchSendDataUnreliable
error:&error];
[self setLastError:error];
}
-(void) match:(GKMatch*)match didReceiveData:(NSData*)data fromPlayer:(NSString*)playerID
{
if ([delegate respondsToSelector:@selector(onReceivedData:fromPlayer:)])
{
[delegate onRecei
超级会员免费看
订阅专栏 解锁全文
72

被折叠的 条评论
为什么被折叠?



