Ejemplo n.º 1
0
void Runner::crouch()
{
    m_state = RunnerStateCrouch;
    this->initShape("crouch");
    this->stopAllActions();
    this->runAction(m_actionCrouch);
    this->scheduleOnce(schedule_selector(Runner::loadNormal), 1.5);
    CocosDenshion::SimpleAudioEngine *audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine();
    audioEngine->playEffect("Sound/crouch.mp3");
}
Ejemplo n.º 2
0
void Runner::jump()
{
    if (m_state == RunnerStateRunning)
	{
        m_state = RunnerStateJumpUp;
        cpBodyApplyImpulse(body, cpv(0, 400), cpv(0, 0));
        this->stopAllActions();
        this->runAction(m_actionJumpUp);
        
        CocosDenshion::SimpleAudioEngine *audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine();
        audioEngine->playEffect("Sound/jump.mp3");
    }
}
int lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect(lua_State* tolua_S)
{
    int argc = 0;
    CocosDenshion::SimpleAudioEngine* cobj = nullptr;
    bool ok  = true;

#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif


#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertype(tolua_S,1,"cc.SimpleAudioEngine",0,&tolua_err)) goto tolua_lerror;
#endif

    cobj = (CocosDenshion::SimpleAudioEngine*)tolua_tousertype(tolua_S,1,0);

#if COCOS2D_DEBUG >= 1
    if (!cobj) 
    {
        tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr);
        return 0;
    }
#endif

    argc = lua_gettop(tolua_S)-1;
    if (argc == 1) 
    {
        const char* arg0;

        std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str();
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr);
            return 0;
        }
        unsigned int ret = cobj->playEffect(arg0);
        tolua_pushnumber(tolua_S,(lua_Number)ret);
        return 1;
    }
    if (argc == 2) 
    {
        const char* arg0;
        bool arg1;

        std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str();

        ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect");
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr);
            return 0;
        }
        unsigned int ret = cobj->playEffect(arg0, arg1);
        tolua_pushnumber(tolua_S,(lua_Number)ret);
        return 1;
    }
    if (argc == 3) 
    {
        const char* arg0;
        bool arg1;
        double arg2;

        std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str();

        ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect");

        ok &= luaval_to_number(tolua_S, 4,&arg2, "cc.SimpleAudioEngine:playEffect");
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr);
            return 0;
        }
        unsigned int ret = cobj->playEffect(arg0, arg1, arg2);
        tolua_pushnumber(tolua_S,(lua_Number)ret);
        return 1;
    }
    if (argc == 4) 
    {
        const char* arg0;
        bool arg1;
        double arg2;
        double arg3;

        std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str();

        ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect");

        ok &= luaval_to_number(tolua_S, 4,&arg2, "cc.SimpleAudioEngine:playEffect");

        ok &= luaval_to_number(tolua_S, 5,&arg3, "cc.SimpleAudioEngine:playEffect");
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr);
            return 0;
        }
        unsigned int ret = cobj->playEffect(arg0, arg1, arg2, arg3);
        tolua_pushnumber(tolua_S,(lua_Number)ret);
        return 1;
    }
    if (argc == 5) 
    {
        const char* arg0;
        bool arg1;
        double arg2;
        double arg3;
        double arg4;

        std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str();

        ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect");

        ok &= luaval_to_number(tolua_S, 4,&arg2, "cc.SimpleAudioEngine:playEffect");

        ok &= luaval_to_number(tolua_S, 5,&arg3, "cc.SimpleAudioEngine:playEffect");

        ok &= luaval_to_number(tolua_S, 6,&arg4, "cc.SimpleAudioEngine:playEffect");
        if(!ok)
        {
            tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr);
            return 0;
        }
        unsigned int ret = cobj->playEffect(arg0, arg1, arg2, arg3, arg4);
        tolua_pushnumber(tolua_S,(lua_Number)ret);
        return 1;
    }
    luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SimpleAudioEngine:playEffect",argc, 1);
    return 0;

#if COCOS2D_DEBUG >= 1
    tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'.",&tolua_err);
#endif

    return 0;
}
Ejemplo n.º 4
0
void CCSWFNodeExt::handleFrameChanged(cocos2d::CCObject * obj){
    CCSWFNode * node = (CCSWFNode *)obj;
    if (m_logicDict) {
        
        CocosDenshion::SimpleAudioEngine * audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine();
        std::stringstream frameKey;
        frameKey << (node->getCurrentFrame() + 1);
        CCDictionary * dict = (CCDictionary *)m_logicDict->objectForKey(frameKey.str());
        if (dict) {
            //切换背景音乐
            CCString * music = (CCString *)dict->objectForKey("music");
            if (music && m_music.compare(music->m_sString) != 0) {
                m_music = music->m_sString;
                if (m_music.length() > 0) {
                    CCLOG("CSWFNodeExt::handleFrameChanged %d playBackgroundMusic %s",node->getCurrentFrame(),m_music.c_str());
                    audioEngine->stopBackgroundMusic(true);
                    audioEngine->preloadBackgroundMusic(m_music.c_str());
                    audioEngine->playBackgroundMusic(m_music.c_str(),true);
                }
            }
            
            //播放音效
            CCString * effect = (CCString *)dict->objectForKey("effect");
            if (effect && effect->length() > 0) {
                const std::string tag = "#";
                std::string srcString = effect->m_sString;
                size_t startPos = srcString.find_first_of(tag);
                if (startPos != std::string::npos) {
                    std::string tmp;
                    do {
                        tmp = srcString.substr(0,startPos);
                        CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),tmp.c_str());
                        audioEngine->preloadEffect(tmp.c_str());
                        audioEngine->playEffect(tmp.c_str(), false);
                        srcString = srcString.substr(startPos+tag.length());
                        startPos = srcString.find_first_of(tag);
                        if(startPos == std::string::npos){
                            CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),tmp.c_str());
                            audioEngine->preloadEffect(tmp.c_str());
                            audioEngine->playEffect(tmp.c_str(), false);
                        }
                    } while(startPos != std::string::npos) ;
                }else{
                    CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),srcString.c_str());
                    audioEngine->preloadEffect(srcString.c_str());
                    audioEngine->playEffect(srcString.c_str(), false);
                }
            }
        }
        
        if (node->getCurrentFrame() == node->getFrameCount() - 1) {
            audioEngine->stopAllEffects();
            if (m_stopBgMusic) {
               audioEngine->stopBackgroundMusic(true);
            }
            CCObject * effectFile = NULL;
            CCARRAY_FOREACH(m_loadEffects, effectFile){
                audioEngine->unloadEffect(((CCString *)effectFile)->getCString());
            }
            m_loadEffects->removeAllObjects();
        }