#include "sprite.h" #include #include "texture.h" // Para Texture // Constructor Sprite::Sprite(std::shared_ptr texture, float pos_x, float pos_y, float width, float height) : texture_(std::move(texture)), pos_((SDL_FRect){pos_x, pos_y, width, height}), sprite_clip_((SDL_FRect){0, 0, pos_.w, pos_.h}) {} Sprite::Sprite(std::shared_ptr texture, SDL_FRect rect) : texture_(std::move(texture)), pos_(rect), sprite_clip_((SDL_FRect){0, 0, pos_.w, pos_.h}) {} Sprite::Sprite(std::shared_ptr texture) : texture_(std::move(texture)), pos_(SDL_FRect{0, 0, static_cast(texture_->getWidth()), static_cast(texture_->getHeight())}), sprite_clip_(pos_) {} // Muestra el sprite por pantalla void Sprite::render() { texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_, zoom_); } // Establece la posición del objeto void Sprite::setPosition(float pos_x, float pos_y) { pos_.x = pos_x; pos_.y = pos_y; } // Establece la posición del objeto void Sprite::setPosition(SDL_FPoint point) { pos_.x = point.x; pos_.y = point.y; } // Reinicia las variables a cero void Sprite::clear() { pos_ = {0, 0, 0, 0}; sprite_clip_ = {0, 0, 0, 0}; }