Afegit zoom a la classe Sprite

This commit is contained in:
2024-12-03 11:39:31 +01:00
parent 1aa0dd3864
commit 3c5bbf2ab0
4 changed files with 33 additions and 128 deletions

View File

@@ -12,6 +12,7 @@ protected:
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite
SDL_Rect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
double zoom_ = 1.0f; // Zoom aplicado a la textura
public:
// Constructor
@@ -28,40 +29,43 @@ public:
// Reinicia las variables a cero
virtual void clear();
// Obten el valor de la variable
int getX() const;
int getY() const;
int getWidth() const;
int getHeight() const;
// Obtiene la posición y el tamaño
int getX() const { return pos_.x; }
int getY() const { return pos_.y; }
int getWidth() const { return pos_.w; }
int getHeight() const { return pos_.h; }
// Devuelve el rectangulo donde está el sprite
SDL_Rect getPosition() const;
SDL_Rect getPosition() const { return pos_; }
// Establece el valor de la variable
void setX(int x);
void setY(int y);
void setWidth(int w);
void setHeight(int h);
// Establece la posición y el tamaño
void setX(int x) { pos_.x = x; }
void setY(int y) { pos_.y = y; }
void setWidth(int w) { pos_.w = w; }
void setHeight(int h) { pos_.h = h; }
// Establece la posición del objeto
void setPosition(int x, int y);
void setPosition(SDL_Point p);
void setPosition(SDL_Rect r);
void setPosition(SDL_Rect r) { pos_ = r; }
// Incrementa el valor de la variable
void incX(int value);
void incY(int value);
// Establece el nivel de zoom
void setZoom(float zoom) { zoom_ = zoom; }
// Obten el valor de la variable
SDL_Rect getSpriteClip() const;
// Aumenta o disminuye la posición
void incX(int value) { pos_.x += value; }
void incY(int value) { pos_.y += value; }
// Establece el valor de la variable
void setSpriteClip(SDL_Rect rect);
void setSpriteClip(int x, int y, int w, int h);
// Obtiene el rectangulo que se dibuja de la textura
SDL_Rect getSpriteClip() const { return sprite_clip_; }
// Obten el valor de la variable
std::shared_ptr<Texture> getTexture() const;
// Establece el rectangulo que se dibuja de la textura
void setSpriteClip(SDL_Rect rect) { sprite_clip_ = rect; }
void setSpriteClip(int x, int y, int w, int h) { sprite_clip_ = (SDL_Rect){x, y, w, h}; }
// Establece el valor de la variable
void setTexture(std::shared_ptr<Texture> texture);
// Obtiene un puntero a la textura
std::shared_ptr<Texture> getTexture() const { return texture_; }
// Establece la textura a utilizar
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
};