void AnimationCommandLayer::onFrameEvent(Frame * frame)
	{

		EventFrame* evnt = dynamic_cast<EventFrame*>(frame);
		std::string aniStr = evnt->getEvent();

		if (!evnt)
		{
			return;
		}

		Sprite* sp = (Sprite*)evnt->getNode();
		if (aniStr != "")//spine动画 compare(0, 3, "spi")
		{
			Player * player = (Player *)sp->getChildByTag(SPINE_ANIMATION_PLAYER_TAG);
			player->playRoleAction(aniStr.c_str(), true);
			CCLOG("%s Spine Animation is %s", player->getName().c_str(), aniStr.c_str());
		}
//暂时去掉下面的代码,如果以后需要执行cocos studio做不出来的动画,那么修改规则,用下面的代码 cuihanbing
// 		else if (str.compare(0, 3, "act") == 0)//需要cocos2d执行的动画
// 		{
// 			if (str == "act_chuxian")
// 			{
// 				evnt->getNode()->setOpacity(256);
// 				CCLOG("Action is %s", str.c_str());
// 			}
// 		}
	}
Beispiel #2
0
void ScoreLabel::setScore(int score)
{
    this->timeline->play("CountUp", false);
    this->timeline->setFrameEventCallFunc([this, score](Frame* frame) {
        EventFrame* frameEvent = dynamic_cast<EventFrame*>(frame);
        auto eventName = frameEvent->getEvent();

        if (eventName == "CountUp") {
            this->scoreLabel->setString(std::to_string(score));
        }
    });
}
Beispiel #3
0
void TestTimelineFrameEvent::onFrameEvent(Frame* frame)
{
    EventFrame* evnt = dynamic_cast<EventFrame*>(frame);
    if(!evnt)
        return;

    std::string str = evnt->getEvent();

    if (str == "changeColor")
    {
        evnt->getNode()->setColor(Color3B(0,0,0));
    }
    else if(str == "endChangeColor")
    {
        evnt->getNode()->setColor(Color3B(255,255,255));
    }
}
Beispiel #4
0
void Entity::attack(const std::string attackName)
{
    if (! this->stateMachine->canAttack()) {
        return;
    }

    if (this->stateMachine->isDead()) {
        return;
    }

    EntityAttackParams attackParams = this->getAttackParamsByName(attackName);
    std::string particleFilePath = attackParams.particleFilePath;

    this->timeline->play(attackName, false);
    this->timeline->setFrameEventCallFunc([this, attackName, particleFilePath](Frame* frame) {
        EventFrame* frameEvent = dynamic_cast<EventFrame*>(frame);
        auto eventName = frameEvent->getEvent();

        // log("---- %s ----", eventName.c_str());
        if (eventName == "Ready") {
            this->currentAttackName = attackName;
            this->stateMachine->readyToAttack();
        } else if (eventName == "Attack") {
            this->stateMachine->startToAttack();

            if (particleFilePath != "") {
                ParticleSystemQuad* particle = ParticleSystemQuad::create(particleFilePath);
                this->addChild(particle);
            }
        } else if (eventName == "Cooldown") {
            this->stateMachine->coolDownAttaking();
        } else if (eventName == "Finish") {
            this->stateMachine->finishAttaking();
            this->currentAttackName = "";
        }
    });
}