From: Daniel Karbach Date: Tue, 2 Oct 2012 20:01:22 +0000 (+0200) Subject: changed how animation runners handle sprite overrides X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;ds=sidebyside;h=a67a3c4f6bc11cd5284d6c5aabf4a3e180517a03;hp=9302f6869530e5492c73ef6f12f9cea348e8b2a6;p=l2e.git changed how animation runners handle sprite overrides --- 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); }