X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FAnimation.h;h=0baba35d915e2ee91754a64a7028a5bb2a82a4e3;hb=2147d00bbcb43f5cb4499091f646057cb6944cb3;hp=ecf71e84f686c82763b6473d817857b8bd19f4a7;hpb=ecaa8da8d8e57da061443aa5cc5a68d353126bf8;p=l2e.git diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index ecf71e8..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,11 +53,11 @@ 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; } - void Clear() { animation = 0; timer = app::Timer(); } + void Clear() { animation = 0; timer = app::Timer(); } void Start(app::State &ctrl) { timer = ctrl.GraphicsTimers().StartInterval(animation->FrameTime()); @@ -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;