2019-11-05 20:45:41 +00:00
|
|
|
#ifndef DEF_XSPRITEANIMATION_H
|
|
|
|
#define DEF_XSPRITEANIMATION_H
|
|
|
|
|
|
|
|
#include "SDL.h"
|
2019-11-06 21:48:25 +00:00
|
|
|
#include <vector>
|
2019-11-05 20:45:41 +00:00
|
|
|
#include "xSprite.h"
|
|
|
|
#include "xApplication.h"
|
|
|
|
#include "xElement.h"
|
2019-11-06 21:48:25 +00:00
|
|
|
#include "xOrchestrable.h"
|
2019-11-05 20:45:41 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2019-11-06 21:48:25 +00:00
|
|
|
class xSpriteAnimation : public xSprite, public xOrchestrable {
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// spritesheet with sprite size
|
|
|
|
xSpriteAnimation(const char *url, SDL_Rect dest);
|
|
|
|
xSpriteAnimation(SDL_Surface *s, SDL_Rect dest);
|
|
|
|
~xSpriteAnimation();
|
|
|
|
|
|
|
|
void addFrame(SDL_Rect clip);
|
|
|
|
void clearFrames();
|
|
|
|
|
|
|
|
// animation control handles
|
2019-11-06 21:48:25 +00:00
|
|
|
void start(uint32_t delay);
|
2019-11-05 20:45:41 +00:00
|
|
|
void stop();
|
|
|
|
|
|
|
|
// implement xElement
|
|
|
|
void draw(SDL_Renderer* renderer) override;
|
|
|
|
|
2019-11-06 21:48:25 +00:00
|
|
|
// implement xOrchestrable
|
|
|
|
void tick(const uint32_t ticks);
|
2019-11-05 20:45:41 +00:00
|
|
|
protected:
|
|
|
|
vector<SDL_Rect> _frames;
|
2019-11-06 21:48:25 +00:00
|
|
|
mutex _mutex_frames;
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
// animation
|
2019-11-06 21:48:25 +00:00
|
|
|
uint32_t _interval;
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|