我需要有一个场景的背景音乐和一个角色的背景音乐,但是当角色做出一些动作时我必须停止它.
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:
这其中有 2 种可能 &推荐?
Which one of this is 2 possible & recommended?
问候!
你说你在使用cocos2d,所以我假设你也在使用cocos2d提供的SimpleAudioEngine
.
You say you're using cocos2d so I've made the assumption that you're also using the SimpleAudioEngine
provided with cocos2d.
使用 SimpleAudioEngine
,无法播放 2 个背景音轨.可以通过一些小的修改来循环效果:
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
消息;ALUInt
.保留对此的参考.您需要它来停止循环.-(void) stopEffectWithHandle:(int) 句柄
,将其接收并传递回 OpenAL
以停止效果.-(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.-编辑-
下面是一些循环效果的代码:
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];
这篇关于Cocos2d 播放2种不同的背景音乐文件或循环播放效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!