Exemplo n.º 1
0
void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
    if (_node == nullptr)
    {
	    return;
    }

    auto innerActiontimeline = static_cast<ActionTimeline*>(_node->getActionByTag(_node->getTag()));
    if( nullptr == innerActiontimeline)
        return;
    
    if (InnerActionType::SingleFrame == _innerActionType)
    {
        innerActiontimeline->gotoFrameAndPause(_singleFrameIndex);
        return;
    }
    
    int innerStart = _startFrameIndex;
    int innerEnd = _endFrameIndex;
    if (_enterWithName)
    {
        if (_animationName == AnimationAllName)
        {
            innerStart = 0;
            innerEnd = innerActiontimeline->getDuration();
        }
        else if(innerActiontimeline->IsAnimationInfoExists(_animationName))
        {
            AnimationInfo info = innerActiontimeline->getAnimationInfo(_animationName);
            innerStart = info.startIndex;
            innerEnd = info.endIndex;
        }
        else
        {
            CCLOG("Animation %s not exists!", _animationName.c_str());
        }
    }
    
    int duration = _timeline->getActionTimeline()->getDuration();
    int odddiff = duration - _frameIndex - innerEnd + innerStart;
    if (odddiff < 0)
    {
       innerEnd += odddiff;
    }
    
    if (InnerActionType::NoLoopAction == _innerActionType)
    {
        innerActiontimeline->gotoFrameAndPlay(innerStart, innerEnd, false);
    }
    else if (InnerActionType::LoopAction == _innerActionType)
    {
        innerActiontimeline->gotoFrameAndPlay(innerStart, innerEnd, true);
    }
}
void ActionTimeline::step(float delta)
{
    if (!_playing || _timelineMap.size() == 0 || _duration == 0)
    {
        return;
    }

    _time += delta * _timeSpeed;
    const float endtoffset = _time - _endFrame * _frameInternal;

    if (endtoffset < _frameInternal)
    {
        _currentFrame = (int)(_time / _frameInternal);
        stepToFrame(_currentFrame);
        if (endtoffset >= 0 && _lastFrameListener != nullptr) // last frame
            _lastFrameListener();
    }
    else
    {
        _playing = _loop;
        if (!_playing)
        {
            _time = _endFrame * _frameInternal;
            if (_currentFrame != _endFrame)
            {
                _currentFrame = _endFrame;
                stepToFrame(_currentFrame);
                if (_lastFrameListener != nullptr)  // last frame
                    _lastFrameListener();
            }
        }
        else
            gotoFrameAndPlay(_startFrame, _endFrame, _loop);
    }
}
Exemplo n.º 3
0
Arquivo: Devil.cpp Projeto: ilhaeYe/MB
void Devil::update(float dt)
{
	if (IsAlive())
	{
		if (isFury == false)
		{
			if (getMaxHp() * 0.5f > getCurrentHp())
			{
				isFury = true;
				fury->setVisible(true);
				auto act = CSLoader::createTimeline("Effect/Rage/Rage.csb");
				act->gotoFrameAndPlay(0, 60, true);
				fury->runAction(act);
				d->setFury(true);
				SoundManager::getInstance()->playMySoundLogic("Fury");
			}
		}

		if (timer != kTimerUp)
			timer -= dt;

		switch (mood)
		{
		case myEnum::kMoods::kMoodStay: MoodStay(dt); break;
		case myEnum::kMoods::kMoodAttack: MoodAttack(dt); break;
		}
	}
}
Exemplo n.º 4
0
bool Card::initCard(Vec2 pos, Node *parent) {
	this->setPosition(pos);

	auto rootNode = CSLoader::createNode(CARD_CSB_NAME);
	this->addChild(rootNode);
	auto action = CSLoader::createTimeline(CARD_CSB_NAME);
	rootNode->runAction(action);
	action->gotoFrameAndPlay(0);

	auto image = rootNode->getChildByName<Sprite *>(CARDIMAGE);
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile(CARD_PLIST_NAME);
	auto cardID = (int)(CCRANDOM_0_1() * 2);
	auto cardName = CsvUtil::getInstance()->getValueForCard(cardID, CARD_CSV_NAME).asString();
	image->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(StringUtils::format("%s.png", cardName.c_str())));

	auto button = rootNode->getChildByName<Button *>(CARDTOUCH_BUTTON);
	button->addClickEventListener([=](Ref *ref) {
		if (DATAOPERATOR->getEffectEnable())
			AUDIOENGINE->playEffect(CLICKEFFECT_NAME);
		this->removeFromParent();
		auto click = ParticleSystemQuad::create(CARD_PARTICLE_NAME);
		click->setPosition(pos);
		parent->addChild(click);

		NotificationCenter::getInstance()->postNotification(cardName);
	});

	return true;
}
void ActionTimeline::play(std::string name, bool loop)
{
    if (_animationInfos.find(name) == _animationInfos.end())
    {
        CCLOG("Can't find animation info for %s", name.c_str());
        return;
    }

    AnimationInfo& index = _animationInfos[name];
    gotoFrameAndPlay(index.startIndex, index.endIndex, loop);
}
Exemplo n.º 6
0
bool MenuScene::init() {
    if (!Layer::init()) return false;


    if (USERDEFAULT->getBoolForKey(NEW_PLAYER_KEY, true)) {
        //玩家第一次进入游戏,做数据初始化操作
        USERDEFAULT->setIntegerForKey(UNLOCK_LEVEL_KEY, 1);
        USERDEFAULT->setIntegerForKey(JEWEL_KEY, 10000);
        USERDEFAULT->setIntegerForKey(GOLD_KEY, 100000);
        USERDEFAULT->setIntegerForKey(MAX_HP_KEY, 100);
        USERDEFAULT->setIntegerForKey(MAX_MP_KEY, 100);
        USERDEFAULT->setStringForKey(SELECTEDBOW_KEY, DEFAULT_BOW);

        USERDEFAULT->setBoolForKey(DEFAULT_BOW, true);
        USERDEFAULT->setBoolForKey(SPEED_1_BOW, false);
        USERDEFAULT->setBoolForKey(SPEED_2_BOW, false);
        USERDEFAULT->setBoolForKey(SPEED_3_BOW, false);
        USERDEFAULT->setBoolForKey(MULTPLE_1_BOW, false);
        USERDEFAULT->setBoolForKey(MULTPLE_2_BOW, false);
        USERDEFAULT->setBoolForKey(MULTPLE_3_BOW, false);
        USERDEFAULT->setBoolForKey(POWER_1_BOW, false);
        USERDEFAULT->setBoolForKey(POWER_2_BOW, false);
        USERDEFAULT->setBoolForKey(POWER_3_BOW, false);
        USERDEFAULT->setBoolForKey(DEMON_BOW, false);

        USERDEFAULT->setBoolForKey(MUSIC_ENABLE_KEY, true);
        USERDEFAULT->setBoolForKey(EFFECT_ENABLE_KEY, true);

        USERDEFAULT->setBoolForKey(NEW_PLAYER_KEY, false);
        USERDEFAULT->flush();
    }

    //初始化数据
    if (DATAOPERATOR->getMusicEnable() && !AUDIOENGINE->isBackgroundMusicPlaying())
        AUDIOENGINE->playBackgroundMusic(MENUSCENE_BGM_NAME, true);

    //_rootNode = CSLoader::createNode(MENUSCENE_CSB_NAME);
    _rootNode = CSLoader::createNode("MenuScene.csb");
    this->addChild(_rootNode);
    auto action = CSLoader::createTimeline(MENUSCENE_CSB_NAME);
    _rootNode->runAction(action);
    action->gotoFrameAndPlay(0, false);

    //初始化按钮
    this->initButton();

    return true;
}
void ActionTimeline::step(float delta)
{
    if (!_playing || _timelineMap.size() == 0 || _duration == 0)
    {
        return;
    }

    _time += delta * _timeSpeed;
    _currentFrame = (int)(_time / _frameInternal);

    stepToFrame(_currentFrame);

    if(_time > _endFrame * _frameInternal)
    {
        _playing = _loop;
        if(!_playing)
            _time = _endFrame * _frameInternal;
        else           
            gotoFrameAndPlay(_startFrame, _endFrame, _loop);
    }

}
void ActionTimeline::start()
{
    gotoFrameAndPlay(0);
}
void ActionTimeline::gotoFrameAndPlay(int startIndex, int endIndex, bool loop)
{
    gotoFrameAndPlay(startIndex, endIndex, startIndex, loop);
}
Exemplo n.º 10
0
void ActionTimeline::gotoFrameAndPlay(int startIndex, bool loop)
{
    gotoFrameAndPlay(startIndex, _duration, loop);
}
Exemplo n.º 11
0
void ActionTimeline::gotoFrameAndPlay(int startIndex)
{
    gotoFrameAndPlay(startIndex, true);
}
	void AnimationCommandLayer::createLayer()
	{
		MusicAudio::getInstance()->stopMusic();

		visibleSize = Director::getInstance()->getVisibleSize();
		Vec2 origin = Director::getInstance()->getVisibleOrigin();

		std::string pathStr = "Animation/";
		if (m_aniType == IntroAnimation)
		{
			pathStr.append("IntroLesson").append(to_string(GameData::getInstance()->voUser->m_lessonId)).append(".csb");
			m_animationVO = m_AnimVO;
		}
		else if (m_aniType == EndAnimation)
		{
			pathStr.append("EndLesson").append(to_string(GameData::getInstance()->voUser->m_lessonId)).append(".csb");
			m_animationVO = m_AnimEndVO;
		}

		CCLOG(pathStr.c_str());
		if (! FileUtils::getInstance()->isFileExist(pathStr))
		{
			CocosToast::createToastWithIconv("此动画文件不存在");
			return;
		}
		MusicAudio::getInstance()->play(m_animationVO->m_AnimBgMusic, 0, true);

		pNode = CSLoader::createNode(pathStr);
		pNode->setPosition(visibleSize.width / 2, visibleSize.height / 2);
		pNode->setAnchorPoint(Vec2(0.5f, 0.5f));
		this->addChild(pNode);

		for (int i = 0; i<m_animationVO->m_SpineAnimVector.size(); i++)
		{
			Player* pPlayer = Player::create(m_animationVO->m_SpineAnimVector[i]);//创建spine动画player
			m_pSpinePlayerVec.push_back(pPlayer);
			Sprite *sp = (Sprite *)(seekWidgetByName(pNode, m_animationVO->m_CocosAnimVector[i]));//从csb获取每一个需要加载动作的精灵
			sp->addChild(pPlayer, 0, SPINE_ANIMATION_PLAYER_TAG);//创建spine动画Player,并加载到相对应的精灵中(绑定)
			m_PlayerVec.push_back(sp);
		}

		auto action = CSLoader::createTimeline(pathStr);
		//帧事件监听 
		action->setFrameEventCallFunc(CC_CALLBACK_1(AnimationCommandLayer::onFrameEvent, this));
		//关于CC_CALLBACK_1需要点C++11的基础才能知道是咋回事,这里只要照着写就行。想了解可以查下std::Bind 
		action->gotoFrameAndPlay(0, false);
		pNode->runAction(action);

		//创建button里面的参数必填,不能设为NULL,就算没有也得用"",因为该函数是形参为引用变量。
		//播放暂停按钮
		Button* playBtn = createButton("image/button/ui_pauseU.png", "", "", Vec2(10, 10), "pause");
		playBtn->setAnchorPoint(Vec2(0, 0));
		this->addChild(playBtn, 10);

		auto theCallBack = [this](Ref* sender, Widget::TouchEventType touchType)->void{

			Button* p = static_cast<Button*>(sender);
			std::string name = p->getName();
			if (touchType == Widget::TouchEventType::ENDED)
			{
				if (p->getName() == "pause")
				{
					CCLOG("Button pause");
					MusicAudio::getInstance()->play("audio/effect/ui_button.wav", 1, false);
					Director::getInstance()->pause();
					SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
					p->loadTextureNormal("image/button/ui_playU.png");
					p->setName("play");
				}
				else if (p->getName() == "play")
				{
					CCLOG("Button play");
					MusicAudio::getInstance()->play("audio/effect/ui_button.wav", 1, false);
					SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
					Director::getInstance()->resume();
					p->loadTextureNormal("image/button/ui_pauseU.png");
					p->setName("pause");
				}
			}
		};
		playBtn->addTouchEventListener(theCallBack);
	}