Game Development Reference
In-Depth Information
To make the method publicly available to other classes, you'll have to declare it in the
GameMenuLayer interface. Add the line highlighted in Listing 11-20 to GameMenuLay-
er.h .
Listing 11-20 . Declaring the increaseHitCount method as public
#import "CCNode.h"
@class GameScene;
@interface GameMenuLayer : CCNode
@property (weak) GameScene* gameScene;
-(void) increaseHitCount;
@end
Just to make this easy, you'll call the increaseHitCount method from the GameS-
cene method responsible for playing the collision sound. Open GameScene.m , and locate
the playCollisionSoundWithPair: method. Add the lines highlighted in Listing
11-21 to the beginning of the method, and leave the existing code unchanged.
Listing 11-21 . Increasing the hit counter when a massive force impacts the player
-(void)
playCollisionSoundWithPair:(CCPhysicsCollisionPair*)pair
{
if (pair.totalKineticEnergy > 0.0)
{
[_gameMenuLayer increaseHitCount];
}
// existing code omitted for brevity ...
}
Whenever there's a decent force acting upon the player, the hit counter will be increased
and the label changes the value it displays. Figure 11-18 shows the German version of the
game.
Search WWH ::




Custom Search