convertit Asset i Audio
This commit is contained in:
@@ -5,39 +5,28 @@
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
#include "moving_sprite.h" // Para MovingSprite
|
||||
class Texture; // lines 9-9
|
||||
class Texture;
|
||||
|
||||
struct Animation
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_FRect> frames; // Cada uno de los frames que componen la animación
|
||||
int speed; // Velocidad de la animación
|
||||
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
|
||||
bool completed; // Indica si ha finalizado la animación
|
||||
int current_frame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
std::string name; // Nombre de la animación
|
||||
std::vector<SDL_FRect> frames; // Frames que componen la animación
|
||||
int speed; // Velocidad de reproducción
|
||||
int loop; // Frame al que vuelve la animación al terminar (-1 para no repetir)
|
||||
bool completed; // Indica si la animación ha finalizado
|
||||
int current_frame; // Frame actual en reproducción
|
||||
int counter; // Contador para la animación
|
||||
|
||||
Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {}
|
||||
};
|
||||
|
||||
using AnimationsFileBuffer = std::vector<std::string>;
|
||||
|
||||
// Carga las animaciones en un vector(Animations) desde un fichero
|
||||
// Carga las animaciones desde un fichero en un vector
|
||||
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path);
|
||||
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
protected:
|
||||
// Variables
|
||||
std::vector<Animation> animations_; // Vector con las diferentes animaciones
|
||||
int current_animation_ = 0; // Animacion activa
|
||||
|
||||
// Calcula el frame correspondiente a la animación actual
|
||||
void animate();
|
||||
|
||||
// Carga la animación desde un vector de cadenas
|
||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(std::shared_ptr<Texture> texture, const std::string &file_path);
|
||||
@@ -48,19 +37,22 @@ public:
|
||||
// Destructor
|
||||
virtual ~AnimatedSprite() override = default;
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() override;
|
||||
// Actualización del objeto
|
||||
void update() override; // Actualiza la animación
|
||||
bool animationIsCompleted(); // Comprueba si la animación ha terminado
|
||||
int getIndex(const std::string &name); // Obtiene el índice de una animación según su nombre
|
||||
|
||||
// Comprueba si ha terminado la animación
|
||||
bool animationIsCompleted();
|
||||
// Manipulación de animaciones
|
||||
void setCurrentAnimation(const std::string &name = "default"); // Establece animación por nombre
|
||||
void setCurrentAnimation(int index = 0); // Establece animación por índice
|
||||
void resetAnimation(); // Reinicia la animación
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(const std::string &name);
|
||||
protected:
|
||||
// Almacenamiento de animaciones
|
||||
std::vector<Animation> animations_; // Vector de animaciones disponibles
|
||||
int current_animation_ = 0; // Índice de la animación activa
|
||||
|
||||
// Establece la animacion actual
|
||||
void setCurrentAnimation(const std::string &name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
|
||||
// Reinicia la animación
|
||||
void resetAnimation();
|
||||
};
|
||||
// Procesos internos
|
||||
void animate(); // Calcula el frame actual de la animación
|
||||
void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user