Game Development Reference
In-Depth Information
also have its own delegate methods. Now, it's time to declare the private interface
of
GameViewController
and follow both
MCBrowserViewControl-
lerDelegate
and
GameSceneDelegate
as shown in this snippet:
@interface GameViewController()
<MCBrowserViewControllerDelegate,
GameSceneDelegate>
@property (nonatomic, strong) GameScene* gameScene;
@end
4. In
viewDidLoad
of
GameViewController
, replace the local scene object
with
self.gameScene
and assign the
gameSceneDelegate
property of
the
GameScene
object as the
GameViewController
, as shown here:
// Create and configure the scene.
self.gameScene = [GameScene
unarchiveFromFile:@"GameScene"];
self.gameScene.scaleMode =
SKSceneScaleModeAspectFill;
self.gameScene.gameSceneDelegate = self;
// Present the scene.
[skView presentScene:self.gameScene];
5. Implement the delegate method of
GameSceneDelegate
, like this:
-
(void)showMCBrowserControllerForSession:(MCSession*)session
serviceType:(NSString*)serviceType
{
MCBrowserViewController* viewController =
[[MCBrowserViewController alloc]
initWithServiceType:serviceType session:session];
viewController.minimumNumberOfPeers = 2;
viewController.maximumNumberOfPeers = 2;
viewController.delegate = self;