precarrega les textures del jugador amb variants de paleta
This commit is contained in:
@@ -1,28 +1,29 @@
|
||||
#include "sprite.h"
|
||||
|
||||
#include <utility> // Para move
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture, float pos_x, float pos_y, float width, float height)
|
||||
: texture_(std::move(texture)),
|
||||
: textures_{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> texture, SDL_FRect rect)
|
||||
: texture_(std::move(texture)),
|
||||
: textures_{texture},
|
||||
pos_(rect),
|
||||
sprite_clip_((SDL_FRect){0, 0, pos_.w, pos_.h}) {}
|
||||
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
: texture_(std::move(texture)),
|
||||
pos_(SDL_FRect{0, 0, static_cast<float>(texture_->getWidth()), static_cast<float>(texture_->getHeight())}),
|
||||
: textures_{texture},
|
||||
pos_(SDL_FRect{0, 0, static_cast<float>(textures_.at(texture_index_)->getWidth()), static_cast<float>(textures_.at(texture_index_)->getHeight())}),
|
||||
sprite_clip_(pos_) {}
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void Sprite::render() {
|
||||
texture_->render(pos_.x, pos_.y, &sprite_clip_, zoom_, zoom_);
|
||||
textures_.at(texture_index_)->render(pos_.x, pos_.y, &sprite_clip_, zoom_, zoom_);
|
||||
}
|
||||
|
||||
// Establece la posición del objeto
|
||||
@@ -41,4 +42,13 @@ void Sprite::setPosition(SDL_FPoint point) {
|
||||
void Sprite::clear() {
|
||||
pos_ = {0, 0, 0, 0};
|
||||
sprite_clip_ = {0, 0, 0, 0};
|
||||
}
|
||||
|
||||
// Cambia la textura activa por índice
|
||||
bool Sprite::setActiveTexture(size_t index) {
|
||||
if (index < textures_.size()) {
|
||||
texture_index_ = index;
|
||||
return true;
|
||||
}
|
||||
return false; // Índice fuera de rango
|
||||
}
|
||||
Reference in New Issue
Block a user