Game Development Reference
In-Depth Information
13. Now, edit the didChangeState delegate method of MCSession , when the
state changes to connected as shown in the following:
- (void)session:(MCSession *)session
didReceiveData:(NSData *)data fromPeer:(MCPeerID
*)peerID {
// Data has been received from a peer.
// Do something with the received data, on the
main thread
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
// Process the data
unsigned char *incomingPacket = (unsigned char
*)[data bytes];
int *pIntData = (int *)&incomingPacket[0];
NetworkPacketCode packetCode =
(NetworkPacketCode)pIntData[1];
switch( packetCode ) {
case KNetworkPacketCodePlayerAllotment:
{
NSInteger gameUniqueId = pIntData[2];
if (gameUniqueIdForPlayerAllocation >
gameUniqueId)
{
self.gameInfoLabel.text =
kFirstPlayerLabelText;
self.localTankSprite =
self.blueTankSprite;
self.remoteTankSprite =
self.redTankSprite;
}
else
{
self.gameInfoLabel.text =
kSecondPlayerLabelText;
self.localTankSprite =
Search WWH ::




Custom Search