Example #1
0
bool Fish::init(FishType type)
{
    _type = type;
    CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), _type);
    CCAnimation* fishAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(animationName->getCString());
    CCAnimate* fishAnimate = CCAnimate::create(fishAnimation);
    fishAnimate->setTag(k_Action_Animate);
    _fishSprite = CCSprite::create();
    this->addChild(_fishSprite);
    _fishSprite->runAction(CCRepeatForever::create(fishAnimate));
    return true;
}
Example #2
0
//-----------------------------------------------------------------------------
bool CFish::init(EFishType type)
{
	//CCAnimation只是用于存放动画,真正让动画播放起来的是动作类CCAnimate
	//CCAnimate只能由CCSprite及其子类播放

	m_type = type;
	CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), m_type);
	CCAnimation* fishAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(animationName->getCString());
	CCAnimate* fishAnimate = CCAnimate::create(fishAnimation);
	fishAnimate->setTag(k_Action_Animate);
	m_fishSprite = CCSprite::create();
	this->addChild(m_fishSprite);
	m_fishSprite->runAction(CCRepeatForever::create(fishAnimate));
	return true;
}
Example #3
0
void AvatarComponent::setAnimation(CCAnimation * animation)
{
    this->stopActionByTag(s_animationTag);
    CC_SAFE_RELEASE_NULL(m_animation);
    
    if (animation != nullptr)
    {
        m_animation = animation;
        m_animation->retain();
        
        this->setSpriteFrame(animation->getFrames().at(0)->getSpriteFrame());
        
        CCAnimate * animate = CCAnimate::create(animation);
        animate->setTag(s_animationTag);
        this->runAction(animate);
    }
}
Example #4
0
void AvatarComponent::resetActions()
{
    m_animatorData->getInitData()->initializeNode(this);
    m_animatorData->getAnimData()->runActions(this, m_animatorDataTags);
    
    // 针对 offset time 的处理
    CCDelayTime * delayTime = m_animatorData->getAnimData()->getDelayTimeAction();
    if (delayTime != nullptr)
    {
        this->setVisible(false);
        
        // 首先延迟 offset time 时间,然后显示动画(一定从第一帧开始)。
        Vector<FiniteTimeAction *> actions;
        actions.pushBack(delayTime);
        actions.pushBack(Show::create());
        actions.pushBack(CallFunc::create([this]{
            this->stopActionByTag(s_animationTag);
            this->setSpriteFrame(m_animation->getFrames().at(0)->getSpriteFrame());
            CCAnimate * animate = CCAnimate::create(m_animation);
            animate->setTag(s_animationTag);
            this->runAction(animate);
        }));
        // 动画播放结束后,继续延迟,直到时间结束后,设置不可见。
        actions.pushBack(DelayTime::create(m_animatorData->getAnimData()->getSumTime() - m_animatorData->getAnimData()->getOffsetTime()));
        actions.pushBack(Hide::create());
        
        Sequence * seq = Sequence::create(actions);
        Action * action = nullptr;
        if (m_animatorData->getAnimData()->isForever())
            action = RepeatForever::create(seq);
        else
            action = seq;
        action->setTag(206);
        this->runAction(action);
    }
}
Example #5
0
void Player::introAction()
{
	currentAnimation->setDelayPerUnit(0.09f);
	currentAnimation->setRestoreOriginalFrame(true);
	currentAnimation->addSpriteFrameWithFileName("yes1.png");
	currentAnimation->addSpriteFrameWithFileName("yes2.png");
	currentAnimation->addSpriteFrameWithFileName("yes3.png");
	currentAnimation->addSpriteFrameWithFileName("yes4.png");
	currentAnimation->addSpriteFrameWithFileName("yes5.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("yes6.png");
	currentAnimation->addSpriteFrameWithFileName("wait7.png");
	currentAnimation->addSpriteFrameWithFileName("wait8.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait12.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait8.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait12.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait8.png");
	currentAnimation->addSpriteFrameWithFileName("wait7.png");
	currentAnimation->addSpriteFrameWithFileName("wait6.png");
	currentAnimation->addSpriteFrameWithFileName("wait5.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
	currentAnimation->addSpriteFrameWithFileName("wait1.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait5.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
	currentAnimation->addSpriteFrameWithFileName("wait1.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait5.png");
	currentAnimation->addSpriteFrameWithFileName("wait6.png");
	currentAnimation->addSpriteFrameWithFileName("wait7.png");
	currentAnimation->addSpriteFrameWithFileName("wait8.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait12.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait8.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait12.png");
	currentAnimation->addSpriteFrameWithFileName("wait11.png");
	currentAnimation->addSpriteFrameWithFileName("wait10.png");
	currentAnimation->addSpriteFrameWithFileName("wait9.png");
	currentAnimation->addSpriteFrameWithFileName("wait8.png");
	currentAnimation->addSpriteFrameWithFileName("wait7.png");
	currentAnimation->addSpriteFrameWithFileName("wait6.png");
	currentAnimation->addSpriteFrameWithFileName("wait5.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
	currentAnimation->addSpriteFrameWithFileName("wait1.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait5.png");
	currentAnimation->addSpriteFrameWithFileName("wait4.png");
	currentAnimation->addSpriteFrameWithFileName("wait3.png");
	currentAnimation->addSpriteFrameWithFileName("wait2.png");
		
	CCAnimate* animate = CCAnimate::create(currentAnimation);
	//CCRepeatForever* repeat = CCRepeatForever::create(animate);
	animate->setTag(333);
	sprite->runAction(animate);
}