diff options
-rw-r--r-- | src/actorsprite.cpp | 2 | ||||
-rw-r--r-- | src/animatedsprite.cpp | 7 | ||||
-rw-r--r-- | src/animatedsprite.h | 2 | ||||
-rw-r--r-- | src/being.cpp | 6 | ||||
-rw-r--r-- | src/compoundsprite.cpp | 11 | ||||
-rw-r--r-- | src/compoundsprite.h | 2 | ||||
-rw-r--r-- | src/imagesprite.h | 3 | ||||
-rw-r--r-- | src/resources/animation.h | 2 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 4 | ||||
-rw-r--r-- | src/sprite.h | 10 |
10 files changed, 43 insertions, 6 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 1e0db70e..e89ba3c8 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -460,7 +460,7 @@ void ActorSprite::loadTargetCursor(const std::string &filename, for (unsigned int i = 0; i < currentImageSet->size(); ++i) { - anim->addFrame(currentImageSet->get(i), 75, + anim->addFrame(currentImageSet->get(i), DEFAULT_FRAME_DELAY, -(currentImageSet->getWidth() / 2), -(currentImageSet->getHeight() / 2)); } diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index fb612f19..000dec55 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -206,6 +206,13 @@ size_t AnimatedSprite::getFrameCount() const return 0; } +int AnimatedSprite::getDuration() const +{ + if (mAnimation) + return mAnimation->getDuration(); + return 0; +} + int AnimatedSprite::getWidth() const { if (mFrame) diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 1c5d6994..a5d91095 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -81,6 +81,8 @@ class AnimatedSprite : public Sprite size_t getFrameCount() const; + int getDuration() const; + private: bool updateCurrentAnimation(unsigned int dt); diff --git a/src/being.cpp b/src/being.cpp index 42043313..4f546f6d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -893,10 +893,12 @@ void Being::logic() ActorSprite::logic(); - // Remove it after 3 secs. TODO: Just play the dead animation before removing + // Remove it after 1.5 secs if the dead animation isn't long enough, + // or simply play it until it's finished. if (!isAlive() && Net::getGameHandler()->removeDeadBeings() && - get_elapsed_time(mActionTime) > 3000) + get_elapsed_time(mActionTime) > std::max(getDuration(), 1500)) { + if (getType() != PLAYER) actorSpriteManager->destroy(this); } diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index d77005c7..5214890c 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -255,6 +255,17 @@ size_t CompoundSprite::getFrameCount(size_t layer) return 0; } +int CompoundSprite::getDuration() const +{ + int duration = 0; + SpriteConstIterator it, it_end; + for (it = begin(), it_end = end(); it != it_end; it++) + if ((*it) && (*it)->getDuration() > duration) + duration = (*it)->getDuration(); + + return duration; +} + static void updateValues(int &dimension, int &pos, int imgDimUL, int imgDimRD, int imgOffset) { // Handle going beyond the left/up diff --git a/src/compoundsprite.h b/src/compoundsprite.h index 3a5e0129..17fdfd18 100644 --- a/src/compoundsprite.h +++ b/src/compoundsprite.h @@ -70,6 +70,8 @@ public: size_t getFrameCount() const; + int getDuration() const; + size_t size() const { return std::vector<Sprite*>::size(); } diff --git a/src/imagesprite.h b/src/imagesprite.h index 3a3678d9..e9f0e7b5 100644 --- a/src/imagesprite.h +++ b/src/imagesprite.h @@ -66,6 +66,9 @@ public: size_t getFrameCount() const { return 1; } + int getDuration() const + { return 0; } + private: Image *mImage; }; diff --git a/src/resources/animation.h b/src/resources/animation.h index 1629aebf..14ba2b27 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -70,7 +70,7 @@ class Animation int getLength() const { return mFrames.size(); } /** - * Returns the duration of this animation. + * Returns the duration of this animation in milliseconds. */ int getDuration() const { return mDuration; } diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 22312107..4375fb89 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -22,6 +22,7 @@ #include "resources/spritedef.h" #include "log.h" +#include "sprite.h" #include "resources/action.h" #include "resources/animation.h" @@ -224,7 +225,8 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, // Get animation frames for_each_xml_child_node(frameNode, animationNode) { - const int delay = XML::getProperty(frameNode, "delay", 0); + const int delay = XML::getProperty(frameNode, "delay", + DEFAULT_FRAME_DELAY); int offsetX = XML::getProperty(frameNode, "offsetX", 0); int offsetY = XML::getProperty(frameNode, "offsetY", 0); diff --git a/src/sprite.h b/src/sprite.h index 797b1b20..096dcf8a 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -26,6 +26,9 @@ class Graphics; class Image; +// Default frame display delay in milliseconds +const int DEFAULT_FRAME_DELAY = 75; + class Sprite { public: @@ -60,7 +63,7 @@ class Sprite virtual bool draw(Graphics* graphics, int posX, int posY) const = 0; /** - * Gets the width in pixels of the image + * Gets the width in pixels of the image */ virtual int getWidth() const = 0; @@ -115,6 +118,11 @@ class Sprite */ virtual size_t getFrameCount() const = 0; + /** + * Returns the duration of the current sprite animation in milliseconds. + */ + virtual int getDuration() const = 0; + protected: float mAlpha; /**< The alpha opacity used to draw */ }; |