This is how you play and stop sound effects in cocos2d
| Embed |
Plain text
Copy this code and paste it in your HTML
- -(Void) playsoundfxfor :( INT) Type
- {
- Switch (type ){
- Case1:
- [[Simpleaudioengine sharedengine] playeffect: @ "snap. caf"];
- Break;
- Case2:
- [[Simpleaudioengine sharedengine] playeffect: @ "erase. caf"];
- Break;
- Case3:
- [[Simpleaudioengine sharedengine] playeffect: @ "boing2.m4a"];
- Break;
- Case4:
- [[Simpleaudioengine sharedengine] playeffect: @ "intro. m4a"];
- Break;
- Case5:
- [[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 ){
-
- Case21:
- Currentfxsoundid = [[simpleaudioengine sharedengine] playeffect: @ "1. m4a"];
- Break;
- Case22:
- Currentfxsoundid = [[simpleaudioengine sharedengine] playeffect: @ "2. m4a"];
- Break;
- Case23:
- Currentfxsoundid = [[simpleaudioengine sharedengine] playeffect: @ "3. m4a"];
- Break;
- Case24:
- Currentfxsoundid = [[simpleaudioengine sharedengine] playeffect: @ "4. m4a"];
- Break;
- Default:
- Break;
- }
- }