From c61de0e168aa0ff5d5f1e429302d1cb2160ac1e4 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 8 Aug 2012 22:01:47 +0200 Subject: [PATCH] added center positioning for Sprite --- src/graphics/Sprite.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index 202b96f..4a99af4 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -8,7 +8,9 @@ #ifndef GRAPHICS_SPRITE_H_ #define GRAPHICS_SPRITE_H_ +#include "../geometry/operators.h" #include "../geometry/Point.h" +#include "../geometry/Vector.h" #include @@ -24,11 +26,13 @@ public: int Width() const { return width; } int Height() const { return height; } void Draw(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const; + void DrawCenter(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const { + geometry::Vector offset(-Width() / 2, -Height() / 2); + Draw(dest, position + offset, col, row); + } void DrawCenterBottom(SDL_Surface *dest, geometry::Point position, int col = 0, int row = 0) const { - geometry::Point translated( - position.X() - (Width() / 2), - position.Y() - Height()); - Draw(dest, translated, col, row); + geometry::Vector offset(-Width() / 2, -Height()); + Draw(dest, position + offset, col, row); } private: -- 2.39.2