You say you're using cocos2d so I've made the assumption that you're also using the SimpleAudioEngine
provided with cocos2d.
With SimpleAudioEngine
, it's not possible to play 2 background tracks. It is possible to loop effects with some small modifications:
- Provide a
-(int) playEffect:(NSString*) file loop:(BOOL) loop
message;
- In this method, you'll need to find out what play effect normally does. The thing you're looking out for is the
ALUInt
that is used as the handle for the sound. Keep a reference to this. You'll need it to stop the loop.
- Provide a
-(void) stopEffectWithHandle:(int) handle
that takes that in and passes it back to OpenAL
to stop the effect.
-EDIT-
Here's some code for looping an effect:
int handle = [[SimpleAudioEngine sharedEngine] playEffect:name];
if (loop) {
alSourcei(handle, AL_LOOPING, 1);
}
return handle;
And some for stopping effects:
[[SimpleAudioEngine sharedEngine] stopEffect:handle];