Game Center与Cocos2d、UIKit视图开发指南
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 onReceivedData:da
超级会员免费看
订阅专栏 解锁全文
31

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



