summaryrefslogtreecommitdiff
path: root/src/animation.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-19 21:24:36 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-11-19 21:24:36 +0000
commit7ac7d0e030464f744546b4e6183a7242f640d5d3 (patch)
treef19831b29511d46e8aba45ace6017c8e6afe815b /src/animation.cpp
parentb7cfcffd7a156e19dfa9882d67426f4fa6edef57 (diff)
downloadmana-7ac7d0e030464f744546b4e6183a7242f640d5d3.tar.gz
mana-7ac7d0e030464f744546b4e6183a7242f640d5d3.tar.bz2
mana-7ac7d0e030464f744546b4e6183a7242f640d5d3.tar.xz
mana-7ac7d0e030464f744546b4e6183a7242f640d5d3.zip
Separated sprite definition from playback.
Diffstat (limited to 'src/animation.cpp')
-rw-r--r--src/animation.cpp56
1 files changed, 5 insertions, 51 deletions
diff --git a/src/animation.cpp b/src/animation.cpp
index a91bdf8d..67fdae11 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -28,74 +28,28 @@
#include "utils/dtor.h"
Animation::Animation():
- mLength(0)
+ mDuration(0)
{
- reset();
-}
-
-void
-Animation::reset()
-{
- mTime = 0;
- iCurrentPhase = mAnimationPhases.begin();
-}
-
-bool
-Animation::update(unsigned int time)
-{
- mTime += time;
- if (mAnimationPhases.empty())
- return true;
- if (isTerminator(*iCurrentPhase))
- return false;
-
- unsigned int delay = iCurrentPhase->delay;
-
- while (mTime > delay)
- {
- if (!delay)
- return true;
- mTime -= delay;
- iCurrentPhase++;
- if (iCurrentPhase == mAnimationPhases.end())
- {
- iCurrentPhase = mAnimationPhases.begin();
- }
- if (isTerminator(*iCurrentPhase))
- return false;
- delay = iCurrentPhase->delay;
- }
- return true;
-}
-
-const AnimationPhase*
-Animation::getCurrentPhase() const
-{
- return mAnimationPhases.empty() ? NULL : &(*iCurrentPhase);
}
void
Animation::addPhase(Image *image, unsigned int delay, int offsetX, int offsetY)
{
// Add new phase to animation list
- AnimationPhase newPhase = { image, delay, offsetX, offsetY};
+ AnimationPhase newPhase = { image, delay, offsetX, offsetY };
mAnimationPhases.push_back(newPhase);
- mLength += delay;
- // Reset animation circle
- iCurrentPhase = mAnimationPhases.begin();
+ mDuration += delay;
}
void
Animation::addTerminator()
{
- AnimationPhase terminator = { NULL, 0, 0, 0};
- mAnimationPhases.push_back(terminator);
- iCurrentPhase = mAnimationPhases.begin();
+ addPhase(NULL, 0, 0, 0);
}
bool
-Animation::isTerminator(AnimationPhase candidate)
+Animation::isTerminator(const AnimationPhase candidate)
{
return (candidate.image == NULL);
}