2013-12-08 17:35:43 +00:00
|
|
|
#include "AnimationController.h"
|
|
|
|
|
2014-04-18 17:19:46 +00:00
|
|
|
AnimationController::AnimationController(Animation* anim, int delay, std::function<void()> finishedCallback, bool reverse)
|
|
|
|
: mAnimation(anim), mFinishedCallback(finishedCallback), mReverse(reverse), mTime(-delay), mDelay(delay)
|
2013-12-08 17:35:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationController::~AnimationController()
|
|
|
|
{
|
|
|
|
if(mFinishedCallback)
|
|
|
|
mFinishedCallback();
|
|
|
|
|
|
|
|
delete mAnimation;
|
|
|
|
}
|
|
|
|
|
2013-12-13 03:17:59 +00:00
|
|
|
bool AnimationController::update(int deltaTime)
|
2013-12-08 17:35:43 +00:00
|
|
|
{
|
|
|
|
mTime += deltaTime;
|
2014-04-18 17:19:46 +00:00
|
|
|
|
|
|
|
if(mTime < 0) // are we still in delay?
|
|
|
|
return false;
|
|
|
|
|
2013-12-08 17:35:43 +00:00
|
|
|
float t = (float)mTime / mAnimation->getDuration();
|
|
|
|
|
|
|
|
if(t > 1.0f)
|
|
|
|
t = 1.0f;
|
|
|
|
else if(t < 0.0f)
|
|
|
|
t = 0.0f;
|
|
|
|
|
|
|
|
mAnimation->apply(mReverse ? 1.0f - t : t);
|
|
|
|
|
|
|
|
if(t == 1.0f)
|
2013-12-13 03:17:59 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2013-12-08 17:35:43 +00:00
|
|
|
}
|