From a67a3c4f6bc11cd5284d6c5aabf4a3e180517a03 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 2 Oct 2012 22:01:22 +0200 Subject: [PATCH] changed how animation runners handle sprite overrides --- src/graphics/Animation.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index cfdb146..4442f89 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -60,7 +60,7 @@ class AnimationRunner { public: explicit AnimationRunner(const Animation *a = 0, int colOffset = 0, int rowOffset = 0) - : animation(a), sprite(a ? a->GetSprite() : 0), colOffset(colOffset), rowOffset(rowOffset) { } + : animation(a), sprite(0), colOffset(colOffset), rowOffset(rowOffset) { } public: bool Valid() const { return animation; } @@ -95,21 +95,24 @@ public: void SetRowOffset(int offset) { rowOffset = offset; } int RowOffset() const { return rowOffset; } + void ChangeAnimation(const Animation *a) { animation = a; } + const Animation *GetAnimation() const { return animation; } + void ChangeSprite(const Sprite *s) { sprite = s; } - const Sprite *GetSprite() const { return sprite; } + const Sprite *GetSprite() const { return sprite ? sprite : animation->GetSprite(); } void Draw(SDL_Surface *dest, geometry::Vector position) const { - sprite->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); + GetSprite()->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); } void DrawTopRight(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-sprite->Width(), 0); + geometry::Vector offset(-GetSprite()->Width(), 0); Draw(dest, position + offset); } void DrawCenter(SDL_Surface *dest, geometry::Vector position) const { - Draw(dest, position - (sprite->Size() / 2)); + Draw(dest, position - (GetSprite()->Size() / 2)); } void DrawCenterBottom(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-sprite->Width() / 2, -sprite->Height()); + geometry::Vector offset(-GetSprite()->Width() / 2, -GetSprite()->Height()); Draw(dest, position + offset); } -- 2.39.2