47 lines
1005 B
C
47 lines
1005 B
C
|
#ifndef DEF_XSPRITEANIMATION_H
|
||
|
#define DEF_XSPRITEANIMATION_H
|
||
|
|
||
|
#include "SDL.h"
|
||
|
#include "xSprite.h"
|
||
|
#include "xApplication.h"
|
||
|
#include "xElement.h"
|
||
|
#include <vector>
|
||
|
#include <thread>
|
||
|
using namespace std;
|
||
|
|
||
|
#define SPRITE_ANIM_ONCE 0b1
|
||
|
#define SPRITE_ANIM_INFINITE 0b10
|
||
|
#define SPRITE_ANIM_REVERSE 0b100
|
||
|
|
||
|
class xSpriteAnimation : public xSprite {
|
||
|
|
||
|
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
|
||
|
void start(int t, int flags=SPRITE_ANIM_ONCE);
|
||
|
void stop();
|
||
|
|
||
|
// implement xElement
|
||
|
void draw(SDL_Renderer* renderer) override;
|
||
|
|
||
|
protected:
|
||
|
vector<SDL_Rect> _frames;
|
||
|
|
||
|
// animation
|
||
|
int _timeout;
|
||
|
int _flags;
|
||
|
|
||
|
// animation thread
|
||
|
thread *_animation;
|
||
|
friend void xSpriteAnimationProcess(xSpriteAnimation *xSA, uint32_t t, int flags);
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif
|