#include "sprite.h" #include "texture.h" // Para Texture // Constructor Sprite::Sprite(std::shared_ptr texture, int x, int y, int w, int h) : texture_(texture), pos_((SDL_Rect){x, y, w, h}), clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {} Sprite::Sprite(std::shared_ptr texture, SDL_Rect rect) : texture_(texture), pos_(rect), clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {} Sprite::Sprite(std::shared_ptr texture) : texture_(texture), pos_({0, 0, texture_->getWidth(), texture_->getHeight()}), clip_(pos_) {} // Muestra el sprite por pantalla void Sprite::render() { texture_->render(pos_.x, pos_.y, &clip_, zoom_, zoom_); } // Establece la posición del objeto void Sprite::setPosition(int x, int y) { pos_.x = x; pos_.y = y; } // Establece la posición del objeto void Sprite::setPosition(SDL_Point p) { pos_.x = p.x; pos_.y = p.y; } // Reinicia las variables a cero void Sprite::clear() { pos_ = {0, 0, 0, 0}; clip_ = {0, 0, 0, 0}; }