diff options
Diffstat (limited to 'src/simpleanimation.cpp')
-rw-r--r-- | src/simpleanimation.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index 48f2f6a5..87ef69e3 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "graphics.h" #include "log.h" #include "simpleanimation.h" @@ -112,17 +113,34 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): mCurrentFrame = mAnimation->getFrame(0); } +bool SimpleAnimation::draw(Graphics* graphics, int posX, int posY) const +{ + if (!mCurrentFrame || !mCurrentFrame->image) + return false; + + return graphics->drawImage(mCurrentFrame->image, + posX + mCurrentFrame->offsetX, + posY + mCurrentFrame->offsetY); +} + +void SimpleAnimation::reset() +{ + mAnimationTime = 0; + mAnimationPhase = 0; +} + void SimpleAnimation::update(unsigned int timePassed) { mAnimationTime += timePassed; - while (mAnimationTime > mCurrentFrame->delay) + + while (mAnimationTime > mCurrentFrame->delay && mCurrentFrame->delay > 0) { mAnimationTime -= mCurrentFrame->delay; mAnimationPhase++; + if (mAnimationPhase >= mAnimation->getLength()) - { mAnimationPhase = 0; - } + mCurrentFrame = mAnimation->getFrame(mAnimationPhase); } } |