在场景中循环播放sfx:
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_timesup.mp3", true);
设置一个 bt 来按下播放另一个 sfx:
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_bt.mp3", false);
它会在按 31 次 bt 后停止循环 sfx。
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
USING_NS_CC;
CCScene* HelloWorld::scene(){
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init(){
if ( !CCLayer::init() ) {
return false;
}
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_timesup.wav", true);
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccp(visibleSize.width/2 ,visibleSize.height/2));
pCloseItem->setScale(10);
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
return true;
}
void HelloWorld::menuCloseCallback(CCObject* pSender){
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_bt.wav", false);
}
在cocosdenshion.mm 这一行:
int sourceIndex = [self _getSourceIndexForSourceGroup:sourceGroupId];
无论是循环播放还是播放都无法识别索引。
点击 bt 31 次后。它将循环声道并结束循环效果。
最佳答案
最后,我终于找到问题并解决了。
需要修改CDAudioManager.m文件中的init函数
添加代码:
[soundEngine setSourceGroupNonInterruptible:0 isNonInterruptible:TRUE];
行后:
soundEngine = [[CDSoundEngine alloc] init];
默认的 cocos2d 声音引擎不检查循环或播放 sfx。现在它会做到这一点。为什么是我:<很难找到。因为game warning sfx stop stringly,然后发现sfx play problem,然后进入黑洞(sound engine):
关于c++ - OpenAl 或 Cocos2dx 存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26945149/