c++ - OpenAl 或 Cocos2dx 存在错误

标签 c++ cocos2d-x openal

在场景中循环播放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/

相关文章:

c++ - wxWidgets 获取显示 wxString(单行)所需的像素数 - wxDC::GetTextExtent 不能是唯一的方法

android - 在 Vivante GC1000 GPU 上编译/链接着色器 (Galaxy Tab 3)

android - CCTMXTiledMap 呈现在不正确的位置 - iOS、Android 和 Win32

ios - 在CCAnimation中获取图像 Cocos2d-x

filter - OpenAL同步

iphone - iPhone 上的 OpenAL 音调生成

c++ - 我是否需要为右值引用显式地重载接受 const 左值引用的方法?

c++ - 为什么非常量指针上的 const Ref 被解释为 const 指针?

c++ - 创建一个类以将摄氏度转换为华氏度,反之亦然

安卓NDK : UnsatisfiedLinkError when using OpenAL shared library