Cocos2d 播放2种不同的背景音乐文件或循环播放效果音乐文件、背景、不同、效果

由网友(你是我的天晴)分享简介:我需要有一个场景的背景音乐和一个角色的背景音乐,但是当角色做出一些动作时我必须停止它.I need to have to have a background music for the Scene and a background music for an Character,but I have to stop i...

我需要有一个场景的背景音乐和一个角色的背景音乐,但是当角色做出一些动作时我必须停止它.

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个背景音乐文件,并停止与角色相关的一个循环播放音效.

这其中有 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 以停止效果. 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.

-编辑-

下面是一些循环效果的代码:

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];
阅读全文

相关推荐

最新文章