This is how you play and stop sound effects in cocos2d
-
- (void)playSoundFXFor:(int)type
-
{
-
switch (type) {
-
case 1:
-
[[SimpleAudioEngine sharedEngine] playEffect:@"snap.caf"];
-
break;
-
case 2:
-
[[SimpleAudioEngine sharedEngine] playEffect:@"Erase.caf"];
-
break;
-
case 3:
-
[[SimpleAudioEngine sharedEngine] playEffect:@"boing2.m4a"];
-
break;
-
case 4:
-
[[SimpleAudioEngine sharedEngine] playEffect:@"intro.m4a"];
-
break;
-
case 5:
-
[[SimpleAudioEngine sharedEngine] playEffect:@"tryAgain.m4a"];
-
break;
-
-
default:
-
break;
-
}
-
-
//Play the tiles narration;
-
if (currentFXSoundID > 0) {
-
//If we currently playing a sound effect, stop it and play the next audio.
-
[[SimpleAudioEngine sharedEngine] stopEffect:currentFXSoundID];
-
}
-
-
//When you call [[SimpleAudioEngine sharedEngine] playEffect:@"mysound.wav"], it actually return an identifier with type ALuint. Save this value, and you can use it to stop the corresponding effect, using [[SimpleAudioEngine sharedEngine] stopEffect:yourEffectId].
-
-
switch (type) {
-
-
case 21:
-
currentFXSoundID = [[SimpleAudioEngine sharedEngine] playEffect:@"1.m4a"];
-
break;
-
case 22:
-
currentFXSoundID = [[SimpleAudioEngine sharedEngine] playEffect:@"2.m4a"];
-
break;
-
case 23:
-
currentFXSoundID = [[SimpleAudioEngine sharedEngine] playEffect:@"3.m4a"];
-
break;
-
case 24:
-
currentFXSoundID = [[SimpleAudioEngine sharedEngine] playEffect:@"4.m4a"];
-
break;
-
default:
-
break;
-
}
-
}