Game Development Reference
In-Depth Information
Here, we set our property to hold a pointer to the player object. At the end of
initWithSize: , we will add the code to handle controller discovery and setup,
and create a pauseLabel , as shown in the following code:
[self configureGameControllers];
self.pauseLabel = [[SKLabelNode alloc] initWithFontNamed:@"Ch
alkduster"];
self.pauseLabel.fontSize = 55;
self.pauseLabel.color = [UIColor whiteColor];
self.pauseLabel.position = CGPointMake(self.size.width / 2,
self.size.height / 2);
self.pauseLabel.zPosition = 110;
[self addChild:self.pauseLabel];
self.pauseLabel.text = @"Pause";
self.pauseLabel.hidden = YES;
Currently, we have not yet written the configureGameControllers method, but we
will do this shortly. The code to create a label should be fairly familiar to you—we
create a label node, set its properties, and set its position to the center of the screen
and hide it, as we don't want it to be visible in the unpaused state of the game.
Each scene has a paused property. When it is set to YES , the scene
stops evaluating actions for all descendants. But the update method
is still getting called! So, you may experience a very strange behavior.
If we pause our game now, all animations will stop, but the
background will still scroll.
The next thing that we need to do is stop updates if the scene is paused. To do that,
change the update method in ERGMyScene.m —add a check for the paused property
at the start of the update method and add the following code:
if (self.paused) {
return;
}
This way, the update method will do something only if the scene is not paused,
which is the intended behavior. If the scene is paused, it will skip all that code and
drop out.
After this, we need the code to find any controllers and use them in our game. To do
this, add the following code to ERGMyScene.m :
- (void)configureGameControllers {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@
selector(gameControllerDidConnect:) name:GCControllerDidConnectNotific
ation object:nil];
 
Search WWH ::




Custom Search