Game Development Reference
In-Depth Information
withName:(NSString *)streamName fromPeer:(MCPeerID
*)peerID {
// Data started being streamed from a peer. (Not
used in this example.)
}
These all are the delegate methods of
MCSession
implemented in the
GameS-
cene
class, amongst which the former two are mostly used. The first one is used
to determine the state of game changes, like, whether it is connected, connecting
or not connected. And the latter one is used to receive data, hence to process that
data under an operation queue block as shown in the above implementation.
10. Now add
instantiateMCSession
in
touchBegan:withEvent
accord-
ing to
gameState
of
GameScene
with
pragma
mark.
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches
withEvent:(UIEvent *)event {
/* Called when a touch begins */
if (self.gameState == kGameStatePlayerToConnect)
{
[self instantiateMCSession];
}
else if (self.gameState == kGameStatePlaying)
{
}
}
In the
touchesBegan
method if the state is
kGameStatePlayerToCon-
nect
then it means that the user has touched to start the game that is, technically
connecting of players to be done and in other states of game the handling would
be done accordingly on touches.
After all these steps an initial session of game set up has been accomplished with
an understanding of multiplayer games' architecture.