4 * Created on: Aug 11, 2012
8 #ifndef GRAPHICS_SIMPLEANIMATION_H_
9 #define GRAPHICS_SIMPLEANIMATION_H_
12 #include "../app/Application.h"
13 #include "../app/State.h"
14 #include "../app/Timer.h"
15 #include "../geometry/Point.h"
21 class SimpleAnimation {
25 : sprite(0), frameTime(0), numFrames(0), col(0), row(0), repeat(false) { }
26 SimpleAnimation(const Sprite *sprite, int frameTime, int numFrames, int col = 0, int row = 0, bool repeat = false)
27 : sprite(sprite), frameTime(frameTime), numFrames(numFrames), col(col), row(row), repeat(repeat) { }
30 void Start(app::State &ctrl) {
31 timer = ctrl.GraphicsTimers().StartInterval(frameTime);
33 void Start(app::Application &ctrl) {
34 timer = ctrl.GlobalTimers().StartInterval(frameTime);
37 timer = app::Timer<Uint32>();
39 bool Running() const {
40 return timer.Running() && (repeat || timer.Iteration() < numFrames);
42 void Draw(SDL_Surface *dest, geometry::Point<int> position) {
43 sprite->Draw(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row);
45 void DrawCenterBottom(SDL_Surface *dest, geometry::Point<int> position) const {
46 sprite->DrawCenterBottom(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row);
51 app::Timer<Uint32> timer;
62 #endif /* GRAPHICS_SIMPLEANIMATION_H_ */