Game Development Reference
In-Depth Information
self.redTankSprite;
self.remoteTankSprite =
self.blueTankSprite;
}
[self
resetLocalTanksAndInfoToInitialState];
break;
}
case KNetworkPacketCodePlayerMove:
{
break;
}
case KNetworkPacketCodePlayerLost:
{
break;
}
default:
break;
}
}];
}
14. In the receiving MCSession method, add all NetworkPacketCode in the
switch case and make changes when the KNetworkPacketCodePlayer-
Allotment packet is received. When allocating the players, set the identity
name accordingly and assign the local and remote sprite objects depending on the
gameUniqueIdForPlayerAllocation . Finally, call a private method re-
setLocalTanksAndInfoToInitialState , in which initial states of both
local and remote sprites with their local data structure are set. All these steps will
be executed on both the connected devices in sessions, which will ensure that
both the devices are in sync.
15. Now once the gameInfoLabel displaying player identity is set, then insert the
code to change the state of the game and to animate gameInfoLabel by hiding
it in the startGame method of GameScene , called by a delegate method of
MCBrowerViewController .
- (void)startGame
{
if (self.gameState == kGameStatePlayerAllotment)
Search WWH ::




Custom Search