/**更新动画*/ void Enemy::updateAnimation(float time) { m_AniFade-=time; m_AniFade=std::max(m_AniFade,0.0f); if (m_pEntity) { Ogre::AnimationStateSet* animStateSet = m_pEntity->getAllAnimationStates(); // 更新自身动画 if (animStateSet) { Ogre::ConstEnabledAnimationStateIterator animStateItor = animStateSet->getEnabledAnimationStateIterator(); while (animStateItor.hasMoreElements()) { Ogre::AnimationState* animState = animStateItor.getNext(); animState->addTime(time); // 当前动画逐渐递增权重 if (animState== m_pAniSate) { if (animState->getWeight() < 1.0f) { animState->setWeight(1.0f - m_AniFade); } } // 其余动画逐渐递减权重,直到关闭动画 else { if (Ogre::Math::RealEqual(animState->getWeight(), 0.0f)) { animState->setWeight(1.0f); animState->setEnabled(false); } else { animState->setWeight(m_AniFade); } } } } } }
void CAnimatedEntity::stopAllAnimations() { if(_entity->getAllAnimationStates()->hasEnabledAnimationState()) { Ogre::ConstEnabledAnimationStateIterator it = _entity->getAllAnimationStates()->getEnabledAnimationStateIterator(); Ogre::AnimationState *animation; //hay que recorrer con el iterador las animaciones una a una y pausarlas while(it.hasMoreElements()) { animation = it.getNext(); animation->setEnabled(false); } // Si había animación activa ya no lo está. _currentAnimation = 0; } } // stopAllAnimations