Fix sprites
This commit is contained in:
parent
b2f888b55f
commit
37d7c962b8
@ -42,16 +42,16 @@ GameRenderer::~GameRenderer()
|
||||
|
||||
std::unique_ptr<Sprite> GameRenderer::load_sprite(const std::string &file, const int width, const int height) const
|
||||
{
|
||||
return std::make_unique<Sprite>(Sprite({ renderer, file, width, height }));
|
||||
return std::make_unique<Sprite>(renderer, file, width, height);
|
||||
}
|
||||
|
||||
void GameRenderer::draw_sprite(const Sprite sprite, const int x, const int y) const
|
||||
void GameRenderer::draw_sprite(const Sprite &sprite, const int x, const int y) const
|
||||
{
|
||||
const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height };
|
||||
SDL_RenderCopy(renderer, sprite.texture, nullptr, &rect);
|
||||
}
|
||||
|
||||
void GameRenderer::draw_sprite_rotated(const Sprite sprite, const int x, const int y, const double angle) const
|
||||
void GameRenderer::draw_sprite_rotated(const Sprite &sprite, const int x, const int y, const double angle) const
|
||||
{
|
||||
const SDL_Rect rect = { .x = x, .y = y, .w = sprite.width, .h = sprite.height };
|
||||
SDL_RenderCopyEx(renderer, sprite.texture, nullptr, &rect, angle, nullptr, SDL_FLIP_NONE);
|
||||
|
||||
@ -24,9 +24,9 @@ public:
|
||||
|
||||
std::unique_ptr<Sprite> load_sprite(const std::string &file, int width, int height) const;
|
||||
|
||||
void draw_sprite(Sprite sprite, int x, int y) const;
|
||||
void draw_sprite(const Sprite &sprite, int x, int y) const;
|
||||
|
||||
void draw_sprite_rotated(Sprite sprite, int x, int y, double angle) const;
|
||||
void draw_sprite_rotated(const Sprite &sprite, int x, int y, double angle) const;
|
||||
|
||||
void clear_screen(uint8_t r, uint8_t g, uint8_t b, uint8_t a) const;
|
||||
|
||||
|
||||
@ -2,22 +2,13 @@
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include "Sprite.hpp"
|
||||
#include <iostream>
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
|
||||
Sprite::Sprite(SDL_Renderer *renderer, const std::string &file, int width, int height) : width(width), height(height)
|
||||
{
|
||||
texture = IMG_LoadTexture(renderer, file.c_str());
|
||||
this->file = std::string(file);
|
||||
}
|
||||
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
std::cout << "destruct " << file << std::endl;
|
||||
|
||||
void *array[10];
|
||||
size_t size = backtrace(array, 10);
|
||||
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
||||
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
@ -9,11 +9,15 @@ public:
|
||||
SDL_Texture *texture;
|
||||
int width;
|
||||
int height;
|
||||
std::string file;
|
||||
|
||||
Sprite(SDL_Renderer *renderer, const std::string &file, int width, int height);
|
||||
|
||||
~Sprite();
|
||||
|
||||
Sprite(const Sprite&) = delete;
|
||||
Sprite operator=(const Sprite&) = delete;
|
||||
Sprite(Sprite&&) = delete;
|
||||
Sprite operator=(Sprite&&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user