summaryrefslogtreecommitdiff
path: root/src/animatedsprite.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2006-09-13 23:17:54 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2006-09-13 23:17:54 +0000
commitc4529dbd7b7f8f3ae5009d35010139e7f1b68deb (patch)
treebf9faa892228e389e34e379ebd306c7fa09a00a6 /src/animatedsprite.cpp
parent4423d208ad7dc1ed3967d715642595f4fd1e6faf (diff)
downloadmana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.tar.gz
mana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.tar.bz2
mana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.tar.xz
mana-c4529dbd7b7f8f3ae5009d35010139e7f1b68deb.zip
some improvements at the animation system
Diffstat (limited to 'src/animatedsprite.cpp')
-rw-r--r--src/animatedsprite.cpp47
1 files changed, 34 insertions, 13 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index a7a4453c..a6d8eaf7 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -92,11 +92,6 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
std::string name = getProperty(node, "name", "");
std::string imageset = getProperty(node, "imageset", "");
- if (name.empty())
- {
- logger->log("Warning: unnamed action in %s",
- animationFile.c_str());
- }
if (mSpritesets.find(imageset) == mSpritesets.end()) {
logger->log("Warning: imageset \"%s\" not defined in %s",
imageset.c_str(),
@@ -108,8 +103,27 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
Action *action = new Action();
- action->setSpriteset(mSpritesets[imageset]);
- mActions[makeSpriteAction(name)] = action;
+ action->setSpriteset(mSpritesets[imageset]);
+
+ SpriteAction actionname = makeSpriteAction(name);
+ if (actionname == ACTION_INVALID)
+ {
+
+ logger->log("Warning: Unknown action \"%s\" defined in %s",
+ name.c_str(),
+ animationFile.c_str());
+ continue;
+ }
+ else {
+ mActions[makeSpriteAction(name)] = action;
+
+ // When first action set it as default direction
+ if (mActions.empty())
+ {
+ mActions[ACTION_DEFAULT] = action;
+ }
+ };
+
// get animations
for (xmlNodePtr animationNode = node->xmlChildrenNode;
@@ -161,6 +175,7 @@ AnimatedSprite::AnimatedSprite(const std::string& animationFile, int variant):
} // for node
// Complete missing actions
+ substituteAction(ACTION_STAND, ACTION_DEFAULT);
substituteAction(ACTION_WALK, ACTION_STAND);
substituteAction(ACTION_WALK, ACTION_RUN);
substituteAction(ACTION_ATTACK, ACTION_STAND);
@@ -278,11 +293,12 @@ AnimatedSprite::update(int time)
if (time < mLastTime || mLastTime == 0)
mLastTime = time;
- // If not enough time have passed yet, do nothing
+ // If not enough time has passed yet, do nothing
if (time > mLastTime && mAction)
{
- Animation *animation = mAction->getAnimation(mDirection);
- animation->update((unsigned int)((time - mLastTime) * mSpeed));
+ Animation *animation = mAction->getAnimation(mDirection);
+ if (animation != NULL) {
+ animation->update((unsigned int)((time - mLastTime) * mSpeed));}
mLastTime = time;
}
}
@@ -293,7 +309,9 @@ AnimatedSprite::draw(Graphics* graphics, Sint32 posX, Sint32 posY) const
if (!mAction)
return false;
- Animation *animation = mAction->getAnimation(mDirection);
+ Animation *animation = mAction->getAnimation(mDirection);
+ if (animation == NULL) return false;
+
int phase = animation->getCurrentPhase();
if (phase < 0)
return false;
@@ -319,7 +337,10 @@ AnimatedSprite::getHeight() const
SpriteAction
AnimatedSprite::makeSpriteAction(const std::string& action)
-{
+{
+ if (action == "" || action == "default") {
+ return ACTION_DEFAULT;
+ }
if (action == "stand") {
return ACTION_STAND;
}
@@ -363,7 +384,7 @@ AnimatedSprite::makeSpriteAction(const std::string& action)
return ACTION_DEAD;
}
else {
- return ACTION_DEFAULT;
+ return ACTION_INVALID;
}
}