Исходный код C++
SDL_Window* SDL_WindowWindow = SDL_CreateWindow("Example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
SDL_Renderer* SDL_RendererRenderer = SDL_CreateRenderer(SDL_WindowWindow, -1, SDL_RENDERER_ACCELERATED);
...
struct structTile {
private: SDL_Texture* SDL_TextureImage;
private: SDL_Rect SDL_RectSourceImage;
private: SDL_Rect SDL_RectWindowImage;
private: SDL_Surface* SDL_SurfaceImage;
public: structTile(void) {
}
public: bool boolSetTexture(std::string stringTexture_ = "", float floatPositionX_ = 0, float floatPositionY_ = 0, float floatSizeW_ = 0, float floatSizeH_ = 0) {
stringTexture = stringTexture_; SDL_SurfaceImage = IMG_Load(stringTexture.c_str());
if (SDL_SurfaceImage == nullptr) {
std::cout << "Error load texture: " << IMG_GetError() << std::endl;
return false;
}
SDL_RectSourceImage.x = floatPositionX_;
SDL_RectSourceImage.y = floatPositionY_;
SDL_RectSourceImage.w = floatSizeW_;
SDL_RectSourceImage.h = floatSizeH_;
return true;
} private: std::string stringTexture = ""; public: std::string stringGetTexture(void) {return stringTexture;}
public: void voidSetPositionX(float floatPositionX_ = 0) {
floatPositionX = floatPositionX_; SDL_RectWindowImage.x = floatPositionX;
} private: float floatPositionX = 0; public: float floatGetPositionX(void) {return floatPositionX;}
public: void voidSetPositionY(float floatPositionY_ = 0) {
floatPositionY = floatPositionY_; SDL_RectWindowImage.y = floatPositionY;
} private: float floatPositionY = 0; public: float floatGetPositionY(void) {return floatPositionY;}
public: void voidRefresh(void) {
SDL_CreateTextureFromSurface(SDL_RendererRenderer, SDL_SurfaceImage);
SDL_FreeSurface(SDL_SurfaceImage);
SDL_RenderCopy(SDL_RendererRenderer, SDL_TextureImage, &SDL_RectSourceImage, &SDL_RectWindowImage);
}
};