Play an animation when changing states

This commit is contained in:
Chris Robinson 2013-01-16 10:45:18 -08:00
parent b378bc92a0
commit 3c487e6019
3 changed files with 35 additions and 10 deletions

View file

@ -169,10 +169,7 @@ namespace MWMechanics
if(!MWWorld::Class::get(ptr).getCreatureStats(ptr).isDead())
mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Idle)));
else
{
mActors.insert(std::make_pair(ptr, CharacterController(ptr, anim, CharState_Dead)));
MWBase::Environment::get().getWorld()->playAnimationGroup (ptr, "death1", 2);
}
}
void Actors::removeActor (const MWWorld::Ptr& ptr)
@ -247,7 +244,6 @@ namespace MWMechanics
}
iter->second.setState(CharState_Dead);
MWBase::Environment::get().getWorld()->playAnimationGroup(iter->first, "death1", 0);
++mDeathCount[MWWorld::Class::get(iter->first).getId(iter->first)];

View file

@ -19,8 +19,41 @@
#include "character.hpp"
#include "../mwrender/animation.hpp"
namespace MWMechanics
{
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state)
: mPtr(ptr), mAnimation(anim), mState(state)
{
if(!mAnimation)
return;
switch(mState)
{
case CharState_Idle:
mAnimation->playGroup("idle", 1, 1);
break;
case CharState_Dead:
mAnimation->playGroup("death1", 1, 1);
break;
}
}
void CharacterController::setState(CharacterState state)
{
mState = state;
switch(mState)
{
case CharState_Idle:
mAnimation->playGroup("idle", 1, 1);
break;
case CharState_Dead:
mAnimation->playGroup("death1", 1, 1);
break;
}
}
}

View file

@ -24,15 +24,11 @@ class CharacterController
CharacterState mState;
public:
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state)
: mPtr(ptr), mAnimation(anim), mState(state)
{ }
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state);
void setState(CharacterState state);
CharacterState getState() const
{ return mState; }
void setState(CharacterState state)
{ mState = state; }
};
}