Game Development Reference
In-Depth Information
Here
gameSession
is the session that will be created for playing a multiplayer
game,
gamePeerID
is the unique ID for the local player of this
gameSes-
sion
, which will be in future acting as the unique ID of the remote player to
whom this device will be connected to. This is why it is called peerID.
Ser-
viceType
is the unique ID assigned particularly to the game; here, the service
type will be TankRace and advertiser is a class that handles all incoming invita-
tions to the user and handles all user responses. A
gameInfoLabel
property is
declared, which will be created to instruct the user to connect with other players.
2. Add a method called
addGameInfoLabelWithText
, which can be used to
show any GameInfo with
pragma
mark.
#pragma mark - Adding Assets Methods
- (void)addGameInfoLabelWithText:(NSString*)labelText
{
if (self.gameInfoLabel == nil) {
self.gameInfoLabel = [SKLabelNode
labelNodeWithFontNamed:@"Chalkduster"];
self.gameInfoLabel.text = labelText;
self.gameInfoLabel.fontSize = 32;
self.gameInfoLabel.position =
CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame));
self.gameInfoLabel.zPosition = 100;
[self addChild:self.gameInfoLabel];
}
}
3. Declare hash defines for different GameInfo texts.
#define kConnectingDevicesText @"Tap to Connect"
#define kGameStartedText @"Game Started"
#define kConnectedDevicesText @"Devices Connected"
4. Call
addGameInfoLabelWithText
from the
didMoveToView
method of
GameScene
. With text hash define
kConnectingDevicesText
and
pragma
mark as depicted below.