void LoadingScene::LoadingMusic()
{
    audioloaded = true;
    auto Audio = CocosDenshion::SimpleAudioEngine::getInstance();
    Audio->preloadEffect("explodeEffect.mp3");
    Audio->preloadEffect("hit.mp3");
    Audio->preloadEffect("boom2.mp3");
    Audio->preloadEffect("boom.mp3");
    Audio->preloadBackgroundMusic("Orbital Colossus_0.mp3");
    //Audio->preloadBackgroundMusic("Star_Chaser.mp3");
    
    // Music By Matthew Pable (http://www.matthewpablo.com/)
    // Licensed under CC-BY 3.0 (http://creativecommons.org/licenses/by/3.0/)
    Audio->playBackgroundMusic("Flux2.mp3");
}
KDuint SimpleAudioEngine::playEffect ( const KDchar* szFilePath, KDbool bLoop, KDfloat fPitch, KDfloat fPan, KDfloat fGain )
{
	if (!szFilePath)
	{
		return 0;
	}

	std::string  sPath = FileUtils::getInstance()->fullPathForFilename(szFilePath);
	KDuint		 uRet = _Hash(sPath.c_str());

	preloadEffect(szFilePath);

	SoundList::iterator it = l_aEffectList.find(uRet);
	if (it != l_aEffectList.end())
	{
		xmSoundSetRepeat(it->second, bLoop);		
		xmSoundSetVolume(it->second, fGain);
		xmSoundSetPitch(it->second, fPitch);
		xmSoundSetPan(it->second, fPan);
		xmSoundRewind(it->second);
	}
	else
	{
		uRet = 0;
	}

	return uRet;
}
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		EffectsMap::iterator iter = s_effects.find(pszFilePath);

		if (iter == s_effects.end())
		{
			preloadEffect(pszFilePath);

			// let's try again
			iter = s_effects.find(pszFilePath);
			if (iter == s_effects.end())
			{
				fprintf(stderr, "could not find play sound %s\n", pszFilePath);
				return -1;
			}
		}

		checkALError("playEffect");
		iter->second->isLooped = bLoop;
		alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
		alSourcePlay(iter->second->source);
		checkALError("playEffect");

		return iter->second->source;
	}
Beispiel #4
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		// Changing file path to full path
    	std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);

		EffectsMap::iterator iter = s_effects.find(fullPath);

		if (iter == s_effects.end())
		{
			preloadEffect(fullPath.c_str());

			// let's try again
			iter = s_effects.find(fullPath);
			if (iter == s_effects.end())
			{
				fprintf(stderr, "could not find play sound %s\n", fullPath.c_str());
				return -1;
			}
		}

		checkALError("playEffect");
		iter->second->isLooped = bLoop;
		alSourcei(iter->second->source, AL_LOOPING, iter->second->isLooped ? AL_TRUE : AL_FALSE);
		alSourcePlay(iter->second->source);
		checkALError("playEffect");

		return iter->second->source;
	}
int SimpleAudioEngine::playEffect(const char* pszFilePath)
{
	int nRet = preloadEffect(pszFilePath);
	if (nRet)
	{
		playPreloadedEffect(nRet);
	}
	return nRet;
}
// for sound effects
int SimpleAudioEngine::playEffect(const char* pszFilePath)
{
    int nSoundID = preloadEffect(pszFilePath);

    if (nSoundID > 0)
    {
        playPreloadedEffect(nSoundID);
    }

    return nSoundID;
}
Beispiel #7
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::createWithRect("UNOLink", Rect(0, 0, 640, 960)); //´´½¨WINDOWS´°¿Ú
        director->setOpenGLView(glview);
	}

    director->getOpenGLView()->setDesignResolutionSize(WIDTH, HEIGHT, ResolutionPolicy::SHOW_ALL); //ÆÁÄ»ÊÊÅä
    director->setDisplayStats(false); //²»ÏÔʾFPS
	director->setAnimationInterval(1.0 / 60); //ÉèÖÃFPS

	srand(time(NULL)); //ÉèÖÃËæ»úÊýÖÖ×Ó

	//Ô¤¼ÓÔØÒôÀÖÒôЧ
	auto audio = SimpleAudioEngine::getInstance();
	audio->preloadBackgroundMusic(BGM);
	audio->preloadEffect(START_LINK_EFFECT);
	audio->preloadEffect(LINK_EFFECT);
	audio->preloadEffect(UNDO_EFFECT);
	audio->preloadEffect(REMOVE_EFFECT);
	audio->preloadEffect(WRONG_REMOVE_EFFECT);
	audio->preloadEffect(GAME_OVER_EFFECT);
	audio->preloadEffect(NEW_RECORD_EFFECT);

	//¼ÓÔØcocos studioµ¼³öµÄÎļþ
    FileUtils::getInstance()->addSearchPath("res");

	//½øÈëStart³¡¾°
    auto scene = StartScene::create();
    director->runWithScene(scene);

    return true;
}
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
{
    unsigned int nRet = _Hash(pszFilePath);

    preloadEffect(pszFilePath);

    EffectList::iterator p = sharedList().find(nRet);
    if (p != sharedList().end())
    {
        p->second->Play((bLoop) ? -1 : 1);
    }

    return nRet;
}
Beispiel #9
0
bool TigerBaseScene::init()
{
    if (!TigerBaseLayer::init())
    {
        return false;
    }
    
    _loadPercentdelegate = nullptr;
    _asyncCompletedCount = 0;
    
    preloadEffect();
    
    return true;
}
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
{
    unsigned int nRet = _Hash(pszFilePath);

	preloadEffect(pszFilePath);

    EffectList::iterator p = s_List.find(nRet);
    if (p != s_List.end())
    {
        p->second.Rewind();
    }

	return nRet;
}
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* = false*/,
        float pitch/* = 1.0f*/, float pan/* = 0.0f*/, float gain/* = 1.0f*/)
{
    unsigned int nRet = _Hash(pszFilePath);

    preloadEffect(pszFilePath);

    EffectList::iterator p = sharedList().find(nRet);
    if (p != sharedList().end())
    {
        p->second->Play(bLoop);
    }

    return nRet;
}
void loadOtherResources(const std::string& filename)
{
    cocos2d::log("load other resource: %s",filename.c_str());
    auto pos = filename.find_first_of(".");
    auto fileType = filename.substr(pos,filename.length()-pos);
    if (fileType == ".plist") {
        cocos2d::SpriteFrameCache::getInstance()->addSpriteFramesWithFile(filename);
    }else if(fileType == ".bg.mp3" || fileType == ".mid"){ //FIXME: 可能是音效哦
        preloadBgMusic(filename.c_str());
    }else if(fileType == ".mp3" || fileType == ".ogg" || fileType == ".caf" || fileType == ".wav"){  //FIXME: 可能是背景音乐哦
        preloadEffect(filename.c_str());
    }/*else if(fileType == ".ExportJson"){//动画
        cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo(filename);
    }*/else{
        cocos2d::log("not supported resource type");
    }
}
unsigned int FmodAudioPlayer::playEffect(const char *pszFilePath, bool bLoop)
{
    FMOD::Channel *pChannel;
    FMOD::Sound   *pSound = NULL;

    do
    {
        pSystem->update();

        map<string, FMOD::Sound *>::iterator l_it = mapEffectSound.find(
            string(pszFilePath));
        if (l_it == mapEffectSound.end())
        {
            //no load it yet
            preloadEffect(pszFilePath);
            l_it = mapEffectSound.find(string(pszFilePath));
        }
        pSound = l_it->second;
        if (pSound == NULL)
        {
            break;
        }

        FMOD_RESULT result = pSystem->playSound(FMOD_CHANNEL_FREE, pSound, true,
                                                &pChannel);

        if (ERRCHECK(result))
        {
            printf("sound effect in %s could not be played", pszFilePath);
            break;
        }

        pChannel->setChannelGroup(pChannelGroup);

        //set its loop
        pChannel->setLoopCount((bLoop) ? -1 : 1);
        result = pChannel->setPaused(false);

        mapEffectSoundChannel[iSoundChannelCount] = pChannel;
        return iSoundChannelCount++;
    } while (0);

    return 0;
}
// for sound effects
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath)
{
    preloadEffect(pszFilePath);
    int nRet = -1;

    do
    {
        tEffectElement* pElement = s_pDataManager->getSoundData(pszFilePath);
        BREAK_IF(! pElement);

        TSoundPlayParameter soundParam;
        soundParam.pSoundData = pElement->pDataBuffer;
        soundParam.dataLen    = pElement->nDataSize;
        soundParam.dataType   = SOUND_TYPE_WAVE;
        soundParam.volume     = (int) (0xFFFF * s_fEffectsVolume);

        nRet = s_pEffectPlayer->Play(soundParam);
    } while (0);

    return (unsigned int) nRet;
}
Beispiel #15
0
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		SoundFxMap::iterator it = g_pSoundFxMap->find(pszFilePath) ;
		
		int16* buff = 0 ;
		if( it==g_pSoundFxMap->end() ) {
			preloadEffect(pszFilePath) ;
		}
		buff = (*g_pSoundFxMap)[pszFilePath].data ;

		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[pszFilePath].size/2, (bLoop ? 0 : 1), 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
			IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", pszFilePath, s3eSoundGetErrorString()));	
		}

		return channel;

	}
bool
HelloWorld::init()
{
    if (!Layer::init())
    {
        return false;
    }

    auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
    audio->preloadBackgroundMusic("sfx/An_Adventure_Awaits.mp3");
    audio->preloadBackgroundMusic("sfx/BEAD.mp3");
    audio->preloadEffect("sfx/sound4.wav");
    audio->preloadEffect("sfx/sound5.wav");
    audio->playBackgroundMusic("sfx/BEAD.mp3");

    Size visibleSize = Director::getInstance()->getVisibleSize();

    auto startGameButton = Label::createWithTTF("Start the game", "fonts/Marker Felt.ttf", 24);
    startGameButton->setPosition(
        Vec2(
            visibleSize.width/2,
            visibleSize.height/2 - startGameButton->getContentSize().height
        )
    );
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->onTouchBegan = [](Touch* touch, Event* event) -> bool {
        auto scene = Game::createScene();
        Director::getInstance()->pushScene(scene);
        return true;
    };
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(
        touchListener,
        startGameButton
    );
    this->addChild(startGameButton, 1);

    return true;
}
Beispiel #17
0
// for sound effects
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* = false*/)
{
	result r = E_FAILURE;
	string strFilePath = fullPathFromRelativePath(pszFilePath);
	unsigned int nRet = _Hash(strFilePath.c_str());

	preloadEffect(pszFilePath);

	EffectList::iterator p = s_List.find(nRet);
	if (p != s_List.end())
	{
		p->second->SetVolume((int) (s_fEffectsVolume * 99));
		int volume = p->second->GetVolume();

    	if (s_fEffectsVolume > 0.0f && volume == 0)
    	{
    		p->second->SetVolume(1);
    	}

	    if (AUDIOOUT_STATE_PLAYING == p->second->GetState())
		{
            return nRet; // Stop waste a lot of time, so just return.
	    	//r = p->second->Stop();
		}

	    if (s_fEffectsVolume > 0.0f)
	    {
	    	r = p->second->Play(bLoop);
	    }

    	if (IsFailed(r))
    	{
    		AppLog("play effect fails, error code = %d", r);
    	}
	}
	return nRet;
}
unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop,
                                           float pitch, float pan, float gain)
{
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);

    EffectsMap::iterator iter = s_effects.find(fullPath);

    if (iter == s_effects.end())
    {
        preloadEffect(fullPath.c_str());

        // let's try again
        iter = s_effects.find(fullPath);
        if (iter == s_effects.end())
        {
            fprintf(stderr, "could not find play sound %s\n", fullPath.c_str());
            return -1;
        }
    }

    checkALError("playEffect:init");

    soundData &d = *iter->second;
    d.isLooped = bLoop;
    d.pitch = pitch;
    d.pan = pan;
    d.gain = gain;
    alSourcei(d.source, AL_LOOPING, d.isLooped ? AL_TRUE : AL_FALSE);
    alSourcef(d.source, AL_GAIN, s_effectVolume * d.gain);
    alSourcef(d.source, AL_PITCH, d.pitch);
    float sourcePosAL[] = {d.pan, 0.0f, 0.0f};//Set position - just using left and right panning
    alSourcefv(d.source, AL_POSITION, sourcePosAL);
    alSourcePlay(d.source);
    checkALError("playEffect:alSourcePlay");

    return d.source;
}
	unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop)
	{
		// Changing file path to full path
		std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFilePath);

		SoundFxMap::iterator it = g_pSoundFxMap->find(fullPath) ;
		
		int16* buff = 0 ;
		if( it==g_pSoundFxMap->end() ) {
			preloadEffect(fullPath.c_str()) ;
		}
		buff = (*g_pSoundFxMap)[fullPath].data ;

		int channel = s3eSoundGetFreeChannel();
		
		s3eSoundChannelPlay(channel, buff, (*g_pSoundFxMap)[fullPath].size/2, (bLoop ? 0 : 1), 0);
		
		if (s3eSoundGetError()!= S3E_SOUND_ERR_NONE) {
			IwAssertMsg(GAME, false, ("Play sound %s Failed. Error Code : %s", fullPath.c_str(), s3eSoundGetErrorString()));	
		}

		return channel;

	}
Beispiel #20
0
bool ComAudio::serialize(void* r)
{
    bool ret = false;
	do
	{
		CC_BREAK_IF(r == nullptr);
		SerData *serData = (SerData *)(r);
		const rapidjson::Value *v = serData->_rData;
		stExpCocoNode *cocoNode = serData->_cocoNode;
		const char *className = nullptr;
		const char *comName = nullptr;
		const char *file = nullptr;
		std::string filePath;
		int resType = 0;
		bool loop = false;
		if (v != nullptr)
		{
			className = DICTOOL->getStringValue_json(*v, "classname");
			CC_BREAK_IF(className == nullptr);
			comName = DICTOOL->getStringValue_json(*v, "name");
			const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
			CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
			file = DICTOOL->getStringValue_json(fileData, "path");
			CC_BREAK_IF(file == nullptr);
			resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
			CC_BREAK_IF(resType != 0);
			loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
		}
		else if (cocoNode != nullptr)
		{
			className = cocoNode[1].GetValue();
			CC_BREAK_IF(className == nullptr);
			comName = cocoNode[2].GetValue();
			stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
			CC_BREAK_IF(!pfileData);
			file = pfileData[0].GetValue();
			CC_BREAK_IF(file == nullptr);
			resType = atoi(pfileData[2].GetValue());
			CC_BREAK_IF(resType != 0);
			loop = atoi(cocoNode[5].GetValue()) != 0? true:false;
			ret = true;
		}
		if (comName != nullptr)
		{
			setName(comName);
		}
		else
		{
			setName(className);
		}
		if (file != nullptr)
		{
            if (strcmp(file, "") == 0)
            {
                continue;
            }
			filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
		}
		if (strcmp(className, "CCBackgroundAudio") == 0)
		{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
			// no MP3 support for CC_PLATFORM_WP8
			std::string::size_type pos = filePath.find(".mp3");
			if (pos  == filePath.npos)
			{
				continue;
			}
			filePath.replace(pos, filePath.length(), ".wav");
#endif
			preloadBackgroundMusic(filePath.c_str());
			setLoop(loop);
			playBackgroundMusic(filePath.c_str(), loop);
		}
		else if(strcmp(className, "CCComAudio") == 0)
		{
			preloadEffect(filePath.c_str());
		}
		else
		{
			CC_BREAK_IF(true);
		}
		ret = true;
	}while (0);
	return ret;
}
Beispiel #21
0
bool GameScene::init()
{
    if (!Layer::init())return false;
    
    
    initPlist();
    initEffect();
    
    //set game status
    Config::getInstance()->setGameSatus(ING);
    Config::getInstance()->setScore(0);//rest score
    
    //loding effect
    auto _SimpleAudioEngine = SimpleAudioEngine::getInstance();
    _SimpleAudioEngine->preloadEffect(air_shoot_effect1);
    _SimpleAudioEngine->preloadEffect(ship_explode_effect0);
    
    //init game map
    //init enemy type
    switch (levelNum)
    {
        case GAMEMAP1://0
            if (Config::getInstance()->getmusicState())
            {
                auto simpleAudio = SimpleAudioEngine::getInstance();
                simpleAudio->preloadBackgroundMusic(battle_bg_stage0);
                simpleAudio->setBackgroundMusicVolume(1.0f);
                simpleAudio->playBackgroundMusic(battle_bg_stage0, true);
            }
            addMap("Map1.png");
            levelScore = BOOS_LEVEL1;
            break;
        case GAMEMAP2://1
            if (Config::getInstance()->getmusicState())
            {
                auto simpleAudio = SimpleAudioEngine::getInstance();
                simpleAudio->preloadBackgroundMusic(battle_bg_stage1);
                simpleAudio->setBackgroundMusicVolume(1.0f);
                simpleAudio->playBackgroundMusic(battle_bg_stage1, true);
            }
            addMap("Map2.png");
            levelScore = BOOS_LEVEL2;
            //add particle
            Kit::addParticle(snow_plist, this, VisibleRect::top());
            break;
        case GAMEMAP3://2
            if (Config::getInstance()->getmusicState())
            {
                auto simpleAudio = SimpleAudioEngine::getInstance();
                simpleAudio->preloadBackgroundMusic(battle_bg_stage2);
                simpleAudio->setBackgroundMusicVolume(1.0f);
                simpleAudio->playBackgroundMusic(battle_bg_stage2, true);
            }
            addMap("Map3.png");
            levelScore = BOOS_LEVEL3;
            break;
            
        case GAMEMAP4://3
            if (Config::getInstance()->getmusicState())
            {
                auto simpleAudio = SimpleAudioEngine::getInstance();
                simpleAudio->preloadBackgroundMusic(battle_bg_stage2);
                simpleAudio->setBackgroundMusicVolume(1.0f);
                simpleAudio->playBackgroundMusic(battle_bg_stage2, true);
            }
            addMap("Map4.png");
            levelScore = BOOS_LEVEL4;
            //add fire paticle
            Kit::addParticle(battle_fire_bg_particle_plist, this, VisibleRect::top());
            break;
        default:
            log("there's no game map to do !");
            return false;
            break;
    }
    
    //add logo one top-left
    auto	logoShip = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(SHIP_FILE_NAME));
    float offset = logoShip->getContentSize().width / 2;
    logoShip->setScale(0.8f);
    auto winsize = Director::getInstance()->getWinSize();
    logoShip->setPosition(Vec2(offset, winsize.height - offset));
    this->addChild(logoShip, SHIP_Z_ORDER);
    
    
    
    //set life value  beside of logoShip
    Config::getInstance()->setShipLife(SHIP_LIFES);
    __String life("X");
    life.appendWithFormat("%02d", Config::getInstance()->getShipLife());
    lifeValue = Label::createWithSystemFont(life.getCString(), "Arial", 12);
    lifeValue->setPosition(Vec2(offset * 3, winsize.height - offset));
    lifeValue->setColor(Color3B::RED);
    this->addChild(lifeValue, SHIP_Z_ORDER);
    
    
    //add score
    __String tempscore("得分:");
    tempscore.appendWithFormat("%07d", Config::getInstance()->getScore());
    score = Label::createWithSystemFont(tempscore.getCString(), "Arial", 12);
    score->setPosition(Vec2(winsize.width - 45, winsize.height - offset));
    score->setColor(Color3B::RED);
    this->addChild(score, SHIP_Z_ORDER);
    
    
    
    
    ship = Ship::creatShip(this, 0, SHIP_LIFE_VALUE);
    auto initPosition = VisibleRect::center();
    ship->setPosition(Vec2(initPosition.x, initPosition.y - 120.0f));
    this->addChild(ship, SHIP_Z_ORDER);
    
    
    //add bone btn
    auto bone_btn_sprite = Sprite::create(btn_bone_res);
    bone_btn_sprite->setScale(0.8f);
    auto bone_btn = MenuItemSprite::create(bone_btn_sprite, nullptr, [&](Ref* _bone_btn){
        
        //处理炸弹效果
        log("bone released ......");
        
        //can shake
        auto j = JumpBy::create(0.5f, Vec2::ZERO, 5, 5);
        this->runAction(j);
        
        auto config = Config::getInstance();
        //remove enemy and bullet
        for (auto bullet : *config->enemy_bullet_list)
        {
            bullet->boneDestory();
        }
        
        for (auto enemy : *config->enemy_list)
        {
            //effect it
            log("effect it ......");
            enemy->boneDestory(this);
        }
        config->enemy_bullet_list->clear();
        config->enemy_list->clear();
        
    });
    auto menue = Menu::create(bone_btn, NULL);
    menue->setPosition(Vec2(35, 200));
    this->addChild(menue, BTN_BACK_Z_ORDER);
    menue->runAction(Kit::creatEaseSineInOut(100.0f));
    
    
    
    
    //add back btn
    auto btn_sprite = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(btn_back_res));
    btn_sprite->setColor(Color3B(0, 245, 255));
    auto btn_back = MenuItemSprite::create(btn_sprite, nullptr, [&](Ref* item){
        auto menuSprite = (MenuItemSprite*)item;
        auto scale = ScaleBy::create(0.2f, 1.1);
        auto jumpToGameLevel = CallFunc::create([](){
            
            auto config=Config::getInstance();
            
            if (config->getmusicState()) SimpleAudioEngine::getInstance()->stopBackgroundMusic();// 停止当前背景音乐
            
            if (config->getmusicState())
            {
                SimpleAudioEngine::getInstance()->playBackgroundMusic(main_bg_stage1, true);
            }
          
            
            Director::getInstance()->replaceScene(TransitionFade::create(1.2f, GameLevelLayer::creatScene()));
        });
        
        //call back
        std::function<void()> releaseResources = [&](){
            this->releaseR();
        };
        menuSprite->runAction(Sequence::create(CallFunc::create(releaseResources), scale, scale->reverse(), jumpToGameLevel, NULL));
    });
    
    
    
    
    menue = Menu::create(btn_back, NULL);
    auto btn_back_position = VisibleRect::rightBottom();
    offset = btn_sprite->getContentSize().width / 2;
    menue->setPosition(Vec2(btn_back_position.x - 50, btn_back_position.y + 25));
    this->addChild(menue, BTN_BACK_Z_ORDER);
    menue->runAction(Kit::creatEaseSineInOut(100.0f));
    
    
    
    
    
    
    //添加敌机
    this->schedule(schedule_selector(GameScene::addEnemy), 2.0f, kRepeatForever, 1.2f);
    
    this->scheduleUpdate();
    
    //初始化地图移动
    this->scheduleOnce(schedule_selector(GameScene::initMoveMap), 1.2f);
    
    
    
    
    return true;
}
Beispiel #22
0
bool ComAudio::serialize(void* r)
{
    bool ret = false;
    do
    {
        CC_BREAK_IF(r == nullptr);
        SerData *serData = (SerData *)(r);
        const rapidjson::Value *v = serData->_rData;
        stExpCocoNode *cocoNode = serData->_cocoNode;
        CocoLoader *cocoLoader = serData->_cocoLoader;
        const char *className = nullptr;
        const char *comName = nullptr;
        const char *file = nullptr;
        std::string filePath;
        int resType = 0;
        bool loop = false;
        if (v != nullptr)
        {
            className = DICTOOL->getStringValue_json(*v, "classname");
            CC_BREAK_IF(className == nullptr);
            comName = DICTOOL->getStringValue_json(*v, "name");
            const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
            CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
            file = DICTOOL->getStringValue_json(fileData, "path");
            CC_BREAK_IF(file == nullptr);
            resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
            CC_BREAK_IF(resType != 0);
            loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
        }
        else if (cocoNode != nullptr)
        {
            className = cocoNode[1].GetValue(cocoLoader);
            CC_BREAK_IF(className == nullptr);
            comName = cocoNode[2].GetValue(cocoLoader);
            stExpCocoNode *pfileData = cocoNode[4].GetChildArray(cocoLoader);
            CC_BREAK_IF(!pfileData);
            file = pfileData[0].GetValue(cocoLoader);
            CC_BREAK_IF(file == nullptr);
            resType = atoi(pfileData[2].GetValue(cocoLoader));
            CC_BREAK_IF(resType != 0);
            loop = atoi(cocoNode[5].GetValue(cocoLoader)) != 0? true:false;
            ret = true;
        }
        if (comName != nullptr)
        {
            setName(comName);
        }
        else
        {
            setName(className);
        }
        if (file != nullptr)
        {
            if (strcmp(file, "") == 0)
            {
                continue;
            }
            filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
        }
        if (strcmp(className, "CCBackgroundAudio") == 0)
        {
            preloadBackgroundMusic(filePath.c_str());
            setLoop(loop);
            playBackgroundMusic(filePath.c_str(), loop);
        }
        else if(strcmp(className, COMPONENT_NAME.c_str()) == 0)
        {
            preloadEffect(filePath.c_str());
        }
        else
        {
            CC_BREAK_IF(true);
        }
        ret = true;
    }while (0);
    return ret;
}