diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2006-07-21 16:50:35 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2006-07-21 16:50:35 +0000 |
commit | 32f625b1e6f74df6ade7e01350dc41256dfea953 (patch) | |
tree | 8d91dbd29d750f57949c1b0a5955b859fb66d08e /src | |
parent | ab3871e98d7fe2f69f0ab99c066f8c7040014731 (diff) | |
download | mana-32f625b1e6f74df6ade7e01350dc41256dfea953.tar.gz mana-32f625b1e6f74df6ade7e01350dc41256dfea953.tar.bz2 mana-32f625b1e6f74df6ade7e01350dc41256dfea953.tar.xz mana-32f625b1e6f74df6ade7e01350dc41256dfea953.zip |
Removed unused code, fixed a numeric conversion, used a more meaningful speed.
Diffstat (limited to 'src')
-rw-r--r-- | src/animation.cpp | 39 | ||||
-rw-r--r-- | src/animation.h | 5 |
2 files changed, 14 insertions, 30 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 diff --git a/src/animation.h b/src/animation.h index 7447b7a8..4f7d57a9 100644 --- a/src/animation.h +++ b/src/animation.h @@ -112,11 +112,6 @@ class AnimatedSprite void play(std::string action, int time); /** - * Sets a new action with a new direction. - */ - void play(std::string action, std::string direction); - - /** * Inform the animation of the passed time so that it can output the * correct animation phase. */ |