46 lines
1.2 KiB
C++
46 lines
1.2 KiB
C++
#include "core/rendering/sprite/sprite.hpp"
|
|
|
|
#include <utility>
|
|
|
|
#include "core/rendering/surface.hpp"
|
|
|
|
Sprite::Sprite() = default;
|
|
|
|
Sprite::Sprite(std::shared_ptr<Surface> surface, float x, float y, float w, float h)
|
|
: surface_(std::move(surface)),
|
|
pos_{.x = x, .y = y, .w = w, .h = h},
|
|
clip_{.x = 0.0F, .y = 0.0F, .w = pos_.w, .h = pos_.h} {}
|
|
|
|
Sprite::Sprite(std::shared_ptr<Surface> surface, SDL_FRect rect)
|
|
: surface_(std::move(surface)),
|
|
pos_(rect),
|
|
clip_{.x = 0.0F, .y = 0.0F, .w = pos_.w, .h = pos_.h} {}
|
|
|
|
Sprite::Sprite(std::shared_ptr<Surface> surface)
|
|
: surface_(std::move(surface)),
|
|
pos_{0.0F, 0.0F, static_cast<float>(surface_->getWidth()), static_cast<float>(surface_->getHeight())},
|
|
clip_(pos_) {}
|
|
|
|
void Sprite::render() {
|
|
surface_->render(static_cast<int>(pos_.x), static_cast<int>(pos_.y), &clip_);
|
|
}
|
|
|
|
void Sprite::setPosition(float x, float y) {
|
|
pos_.x = x;
|
|
pos_.y = y;
|
|
}
|
|
|
|
void Sprite::setPosition(SDL_FPoint p) {
|
|
pos_.x = p.x;
|
|
pos_.y = p.y;
|
|
}
|
|
|
|
void Sprite::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};
|
|
}
|
|
|
|
void Sprite::update(float delta_time) {
|
|
(void)delta_time;
|
|
}
|