From: Daniel Karbach Date: Mon, 20 Aug 2012 21:49:19 +0000 (+0200) Subject: yet more stuff for AnimationRunner X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7d27966b2b6fa73c8491130c65cf03929c225960;p=l2e.git yet more stuff for AnimationRunner --- diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index 97230f5..0baba35 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -32,7 +32,6 @@ public: public: const Sprite *GetSprite() const { return sprite; } - void ChangeSprite(const Sprite *s) { sprite = s; } int FrameTime() const { return frameTime; } bool Repeat() const { return repeat; } @@ -54,7 +53,7 @@ class AnimationRunner { public: explicit AnimationRunner(const Animation *a = 0, int colOffset = 0, int rowOffset = 0) - : animation(a), colOffset(colOffset), rowOffset(rowOffset) { } + : animation(a), sprite(a ? a->GetSprite() : 0), colOffset(colOffset), rowOffset(rowOffset) { } public: bool Valid() const { return animation; } @@ -89,19 +88,22 @@ public: void SetRowOffset(int offset) { rowOffset = offset; } int RowOffset() const { return rowOffset; } + void ChangeSprite(const Sprite *s) { sprite = s; } + const Sprite *GetSprite() const { return sprite; } + void Draw(SDL_Surface *dest, geometry::Point position) const { - animation->GetSprite()->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); + sprite->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); } void DrawTopRight(SDL_Surface *dest, geometry::Point position) const { - geometry::Vector offset(-animation->GetSprite()->Width(), 0); + geometry::Vector offset(-sprite->Width(), 0); Draw(dest, position + offset); } void DrawCenter(SDL_Surface *dest, geometry::Point position) const { - geometry::Vector offset(-animation->GetSprite()->Width() / 2, -animation->GetSprite()->Height() / 2); + geometry::Vector offset(-sprite->Width() / 2, -sprite->Height() / 2); Draw(dest, position + offset); } void DrawCenterBottom(SDL_Surface *dest, geometry::Point position) const { - geometry::Vector offset(-animation->GetSprite()->Width() / 2, -animation->GetSprite()->Height()); + geometry::Vector offset(-sprite->Width() / 2, -sprite->Height()); Draw(dest, position + offset); } @@ -109,6 +111,7 @@ public: private: const Animation *animation; + const graphics::Sprite *sprite; app::Timer timer; int colOffset; int rowOffset;