I need to have to have a background music for the Scene and a background music for an Character,but I have to stop it when the character makes some actions.
For this problem I have to options:
Which one of this is 2 possible & recommended?
Regards!
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:
-(int) playEffect:(NSString*) file loop:(BOOL) loop
message;ALUInt
that is used as the handle for the sound. Keep a reference to this. You'll need it to stop the loop.-(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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With