56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#include "core/rendering/surface_sprite.hpp"
|
|
|
|
#include <utility>
|
|
|
|
#include "core/rendering/surface.hpp" // Para Surface
|
|
|
|
// Constructor
|
|
SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface, float x, float y, float w, float h)
|
|
: surface_(std::move(surface)),
|
|
pos_{x, y, w, h},
|
|
clip_{0.0F, 0.0F, pos_.w, pos_.h} {}
|
|
|
|
SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface, SDL_FRect rect)
|
|
: surface_(std::move(surface)),
|
|
pos_(rect),
|
|
clip_{0.0F, 0.0F, pos_.w, pos_.h} {}
|
|
|
|
SurfaceSprite::SurfaceSprite() = default;
|
|
|
|
SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface)
|
|
: surface_(std::move(surface)),
|
|
pos_{0.0F, 0.0F, surface_->getWidth(), surface_->getHeight()},
|
|
clip_(pos_) {}
|
|
|
|
// Muestra el sprite por pantalla
|
|
void SurfaceSprite::render() {
|
|
surface_->render(pos_.x, pos_.y, &clip_);
|
|
}
|
|
|
|
void SurfaceSprite::render(Uint8 source_color, Uint8 target_color) {
|
|
surface_->renderWithColorReplace(pos_.x, pos_.y, source_color, target_color, &clip_);
|
|
}
|
|
|
|
// Establece la posición del objeto
|
|
void SurfaceSprite::setPosition(float x, float y) {
|
|
pos_.x = x;
|
|
pos_.y = y;
|
|
}
|
|
|
|
// Establece la posición del objeto
|
|
void SurfaceSprite::setPosition(SDL_FPoint p) {
|
|
pos_.x = p.x;
|
|
pos_.y = p.y;
|
|
}
|
|
|
|
// Reinicia las variables a cero
|
|
void SurfaceSprite::clear() {
|
|
pos_ = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
|
|
clip_ = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
|
|
}
|
|
|
|
// Actualiza el estado del sprite (time-based)
|
|
void SurfaceSprite::update(float delta_time) {
|
|
// Base implementation does nothing (static sprites)
|
|
(void)delta_time; // Evita warning de parámetro no usado
|
|
} |