Game Development Reference
In-Depth Information
}
-(BOOL) ccPhysicsCollisionBegin:(CCPhysicsCollisionPair
*)pair
player:(CCNode *)player
gear:(CCNode*)gear
{
[self playCollisionSoundWithPair:pair];
return YES;
}
In order for the latter two collision methods to be called, you will have to open Chain.ccb ,
Rope.ccb , and Gear1.ccb in SpriteBuilder. Then edit the corresponding physics Collision
type for the chain and rope elements and for the gear's physics body. The Collision type
for Chain and Rope should be obstacle , and the collision type for Gear should be gear .
If you play the game now, you should at least hear the occasional sound effect playing, in
particular when touching springs. The current setup isn't great sound design, but it shows
the basic principle of playing sound and determining the force of an impact.
Not Playing Sound Effects for a Short While
A common problem when playing sound effects for game events—specifically, if there
are physics collisions involved—is that sound effects may play repeatedly in a short time
frame. Either the new sound always cuts off the previous one or the new sounds add to the
already-playing sounds, increasing the volume and general noisiness of the effect. Both
are generally undesirable.
With OALSimpleAudio , there is no way to determine whether a given sound effect is
still playing or to be notified of its completion. Instead, you have to add a BOOL ivar that
you flip on when playing the sound and flip off after a short time period.
Add the ivar shown in Listing 11-9 to GameScene.m .
Listing 11-9 . Adding the play sound flag
@implementation GameScene
{
// existing ivars omitted ...
BOOL _playingCollisionSound;
}
Search WWH ::




Custom Search