summaryrefslogtreecommitdiff
path: root/src/simpleanimation.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-02-10 12:26:57 -0700
committerIra Rice <irarice@gmail.com>2009-02-10 12:26:57 -0700
commit02e60b55b359002ae1f26f36b40f8fa78ea1a708 (patch)
tree0264392528cf174e2275bb79a84472b77c5245d2 /src/simpleanimation.cpp
parenta8a992ade40c9d68c9faec1cc3a54e7f064fb9d5 (diff)
downloadmana-02e60b55b359002ae1f26f36b40f8fa78ea1a708.tar.gz
mana-02e60b55b359002ae1f26f36b40f8fa78ea1a708.tar.bz2
mana-02e60b55b359002ae1f26f36b40f8fa78ea1a708.tar.xz
mana-02e60b55b359002ae1f26f36b40f8fa78ea1a708.zip
Simplified target drawing so that it actually uses the SimpleAnimation
that it creates when initializing the target cursors in the first place. This behavior was carried over in the first place from the Viewport class. Also moved target drawing responsibility from the map to the being being targeted in the first place. This allows for assuring that targets are always drawn below the sprite being targeted (which the previous solution was designed to do, but didn't do correctly). Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/simpleanimation.cpp')
-rw-r--r--src/simpleanimation.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 9066ed7f..030619ce 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,42 @@ 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)
{
+ // Avoid freaking out at first frame or when tick_time overflows
+ if (timePassed < mLastTime || mLastTime == 0)
+ mLastTime = timePassed;
+
+ // If not enough time has passed yet, do nothing
+ if (timePassed <= mLastTime || !mAnimation)
+ return;
+
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);
}
}