Actualizado animatedsprite.cpp
This commit is contained in:
@@ -11,28 +11,37 @@
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
|
||||
// Clase AnimatedSprite
|
||||
struct animation_t
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> 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 currentFrame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
};
|
||||
|
||||
struct animatedSprite_t
|
||||
{
|
||||
std::vector<animation_t> animations; // Vector con las diferentes animaciones
|
||||
Texture *texture; // Textura con los graficos para el sprite
|
||||
};
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose = false);
|
||||
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
private:
|
||||
struct t_animation
|
||||
{
|
||||
std::string name; // Nombre de la animacion
|
||||
std::vector<SDL_Rect> 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 currentFrame; // Frame actual
|
||||
int counter; // Contador para las animaciones
|
||||
};
|
||||
|
||||
// Variables
|
||||
std::vector<t_animation> animation; // Vector con las diferentes animaciones
|
||||
std::vector<animation_t> animation; // Vector con las diferentes animaciones
|
||||
int currentAnimation; // Animacion activa
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
|
||||
AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation);
|
||||
|
||||
// Destructor
|
||||
~AnimatedSprite();
|
||||
@@ -65,15 +74,12 @@ public:
|
||||
bool animationIsCompleted();
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
||||
SDL_Rect getAnimationClip(int indexA, Uint8 indexF);
|
||||
SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0);
|
||||
SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0);
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int getIndex(std::string name);
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
bool loadFromFile(std::string filePath);
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool loadFromVector(std::vector<std::string> *source);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user