2019-11-05 20:45:41 +00:00
|
|
|
#ifndef DEF_XSPRITE_H
|
|
|
|
#define DEF_XSPRITE_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <mutex>
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_image.h"
|
2020-02-02 15:18:12 +00:00
|
|
|
#include "xDrawable.h"
|
2019-11-08 20:28:36 +00:00
|
|
|
#include "xApplication.h"
|
2019-11-05 20:45:41 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2020-02-02 15:18:12 +00:00
|
|
|
class xSprite : public xDrawable{
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
public:
|
2019-11-08 20:28:36 +00:00
|
|
|
// color sprite
|
|
|
|
xSprite(const int rgba[]);
|
|
|
|
// image sprite
|
|
|
|
xSprite(const char *url);
|
|
|
|
// image with default clip
|
|
|
|
xSprite(const char *url, SDL_Rect clip);
|
|
|
|
virtual ~xSprite();
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
// replace surface
|
|
|
|
void setSurface(const int rgba[]); // color sprite
|
|
|
|
void setSurface(const char *url); // image sprite
|
|
|
|
void setSurface(SDL_Surface *t); // copy surface
|
|
|
|
|
2019-11-08 20:28:36 +00:00
|
|
|
// sets the sprite clip
|
|
|
|
void setClip(SDL_Rect clip);
|
2019-11-05 20:45:41 +00:00
|
|
|
|
2019-11-08 20:28:36 +00:00
|
|
|
// set projection into scene
|
|
|
|
void project(SDL_Rect dest);
|
2019-11-05 20:45:41 +00:00
|
|
|
|
2020-02-02 15:18:12 +00:00
|
|
|
// implement xDrawable
|
2019-11-05 20:45:41 +00:00
|
|
|
virtual void draw(SDL_Renderer* renderer) override;
|
2020-02-02 15:18:12 +00:00
|
|
|
private:
|
2019-11-08 20:28:36 +00:00
|
|
|
SDL_Surface* _surface = NULL;
|
2020-02-02 15:18:12 +00:00
|
|
|
SDL_Rect _clip;
|
2019-11-08 20:28:36 +00:00
|
|
|
SDL_Rect _projection;
|
|
|
|
|
|
|
|
mutex _mutex;
|
2019-11-05 20:45:41 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|