Game Development Reference
In-Depth Information
How to do it...
Before starting with the multiplayer code we should make the game ready for it. First, go in
to the GameScene class and remove the sample SKLabelNode addition code in the
overridden method didMoveToView of GameScene where we usually set up the scene.
Secondly, remove the for loop of touches from the touchesBegan:withEvent
method, which does the addition of SKSpriteNode and its action.
Our project is now ready to start with the multiplayer. Multiplayer games can be developed
in several ways. They can be either played using Bluetooth, Wifi, Internet, or GameCenter.
All these techniques allow us to interconnect devices and share data across devices. This
allows us to show the movement of players in real time. You might have seen the respons-
iveness in multiplayer games. They are really seamless. In this section we will explore
more about multiplayer games and their implementation in iOS. Here we will be instantiat-
ing a session (that is, MCSession) for the local player, which will further connect to another
player in this recipe. Also, to instruct the user to touch we will add an info label saying
Tap to connect and further will implement the delegates of MCSession following
with the explanation of Multiplayer Game States. Stated below are the steps to accomplish
this task:
1. Open GameScene.m file, and create an interface with properties of InfoLabel
and all related session stuff. Also make GameScene follow MCSes-
sionDelegate and the interface will look like this:
@interface GameScene() <MCSessionDelegate>
@property (nonatomic, strong) MCSession* gameSession;
@property (nonatomic, strong) MCPeerID* gamePeerID;
@property (nonatomic, strong) NSString* serviceType;
@property (nonatomic, strong) MCAdvertiserAssistant*
advertiser;
@property (nonatomic, strong) SKLabelNode*
gameInfoLabel;
@end
Search WWH ::




Custom Search