53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#ifndef DEF_XSPRITE_H
|
|
#define DEF_XSPRITE_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include "SDL.h"
|
|
#include "SDL_image.h"
|
|
#include "xDrawable.h"
|
|
#include "xApplication.h"
|
|
using namespace std;
|
|
|
|
class xSprite : public xDrawable{
|
|
|
|
public:
|
|
// color sprite
|
|
xSprite(const int rgba[]);
|
|
// image sprite
|
|
xSprite(const char *url);
|
|
// image with default clip
|
|
xSprite(const char *url, SDL_Rect clip);
|
|
// image with default clip and projection
|
|
xSprite(const char *url, SDL_Rect clip, SDL_Rect projection);
|
|
virtual ~xSprite();
|
|
|
|
// replace surface
|
|
void setSurface(const int rgba[]); // color sprite
|
|
void setSurface(const char *url); // image sprite
|
|
void setSurface(SDL_Surface *t); // copy surface
|
|
SDL_Surface* surface();
|
|
|
|
// sets the sprite clip
|
|
void setClip(SDL_Rect clip);
|
|
void setClip(int x, int y, int w, int h);
|
|
SDL_Rect clip();
|
|
|
|
// set projection into scene
|
|
void project(SDL_Rect dest);
|
|
void project(int x, int y, int w, int h);
|
|
SDL_Rect projection();
|
|
|
|
// implement xDrawable
|
|
virtual void draw(SDL_Renderer* renderer) override;
|
|
private:
|
|
SDL_Surface* _surface = NULL;
|
|
SDL_Rect _clip;
|
|
SDL_Rect _projection;
|
|
|
|
mutex _mutex;
|
|
|
|
};
|
|
|
|
#endif |