summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--src/animation.cpp39
-rw-r--r--src/animation.h5
3 files changed, 19 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 0fd653e7..ffd0f7f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-07-21 Eugenio Favalli <elvenprogrammer@gmail.com>
+
+ * src/animation.cpp, src/animation.h: Removed unused code, fixed a
+ numeric conversion, used a more meaningful speed.
+
2006-07-20 Eugenio Favalli <elvenprogrammer@gmail.com>
* data/help/header.txt, data/help/skills.txt, docs/FAQ.txt, README:
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.
*/