summaryrefslogtreecommitdiff
path: root/src/animation.cpp
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2006-07-21 16:50:35 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2006-07-21 16:50:35 +0000
commit32f625b1e6f74df6ade7e01350dc41256dfea953 (patch)
tree8d91dbd29d750f57949c1b0a5955b859fb66d08e /src/animation.cpp
parentab3871e98d7fe2f69f0ab99c066f8c7040014731 (diff)
downloadmana-client-32f625b1e6f74df6ade7e01350dc41256dfea953.tar.gz
mana-client-32f625b1e6f74df6ade7e01350dc41256dfea953.tar.bz2
mana-client-32f625b1e6f74df6ade7e01350dc41256dfea953.tar.xz
mana-client-32f625b1e6f74df6ade7e01350dc41256dfea953.zip
Removed unused code, fixed a numeric conversion, used a more meaningful speed.
Diffstat (limited to 'src/animation.cpp')
-rw-r--r--src/animation.cpp39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/animation.cpp b/src/animation.cpp
index d3fa7ce2..129ab4bf 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -51,10 +51,10 @@ Animation::update(unsigned int time)
mTime += time;
if (!mAnimationPhases.empty())
{
- while ((mTime > (*iCurrentPhase).delay) &&
- (*iCurrentPhase).delay > 0)
+ unsigned int delay = iCurrentPhase->delay;
+ while (mTime > delay && delay > 0)
{
- mTime -= (*iCurrentPhase).delay;
+ mTime -= delay;
iCurrentPhase++;
if (iCurrentPhase == mAnimationPhases.end())
{
@@ -73,7 +73,7 @@ Animation::getCurrentPhase()
}
else
{
- return (*iCurrentPhase).image;
+ return iCurrentPhase->image;
}
}
@@ -103,7 +103,6 @@ Animation::getLength()
length += (*i).delay;
}
}
- printf("length: %i\n", length);
return length;
}
@@ -346,33 +345,23 @@ AnimatedSprite::play(std::string action, int time)
Action *nextAction = mActions[mAction];
Animation *animation = nextAction->getAnimation(mDirection);
animationLength = animation->getLength();
- if (animationLength)
- {
- mSpeed = time / animationLength;
- }
- else
- {
- mSpeed = 1.0f;
- }
-}
-
-void
-AnimatedSprite::play(std::string action, std::string direction)
-{
- play(action);
- mDirection = direction;
+ mSpeed = (float)animationLength / time;
}
void
AnimatedSprite::update(int time)
{
- //avoid freaking out at first frame or when tick_time overflows
+ // avoid freaking out at first frame or when tick_time overflows
if (time < mLastTime || mLastTime == 0) mLastTime = time;
- Action *action = mActions[mAction];
- Animation *animation = action->getAnimation(mDirection);
- animation->update((unsigned int)((time - mLastTime) / mSpeed));
- mLastTime = time;
+ // if not enough time have passed yet, do nothing
+ if (time > mLastTime)
+ {
+ Action *action = mActions[mAction];
+ Animation *animation = action->getAnimation(mDirection);
+ animation->update((time - mLastTime) * mSpeed, mSpeed);
+ mLastTime = time;
+ }
}
bool