73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
#pragma once
|
|
#include <SDL2/SDL.h>
|
|
#include "movingsprite.h"
|
|
#include <vector>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <fstream>
|
|
|
|
#ifndef ANIMATEDSPRITE_H
|
|
#define ANIMATEDSPRITE_H
|
|
|
|
// Clase AnimatedSprite
|
|
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
|
|
bool loop; // Indica si la animación se reproduce en bucle
|
|
bool completed; // Indica si ha finalizado la animación
|
|
int currentFrame; // Frame actual
|
|
int counter; // Contador para las animaciones
|
|
};
|
|
std::vector<t_animation> animation; // Vector con las diferentes animaciones
|
|
int currentAnimation; // Animacion activa
|
|
|
|
public:
|
|
// Constructor
|
|
AnimatedSprite(LTexture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file="");
|
|
|
|
// Destructor
|
|
~AnimatedSprite();
|
|
|
|
// Calcula el frame correspondiente a la animación actual
|
|
void animate();
|
|
|
|
// Establece el frame actual de la animación
|
|
void setCurrentFrame(std::string name, int num);
|
|
|
|
// Establece el valor del contador
|
|
void setAnimationCounter(std::string name, int num);
|
|
|
|
// Establece la velocidad de una animación
|
|
void setAnimationSpeed(std::string name, int speed);
|
|
|
|
// Establece si la animación se reproduce en bucle
|
|
void setAnimationLoop(std::string name, bool loop);
|
|
|
|
// Establece el valor de la variable
|
|
void setAnimationCompleted(std::string name, bool value);
|
|
|
|
// Comprueba si ha terminado la animación
|
|
bool animationIsCompleted(std::string name);
|
|
|
|
// Devuelve el rectangulo de una animación y frame concreto
|
|
SDL_Rect getAnimationClip(std::string name, Uint8 index);
|
|
|
|
// Obtiene el indice de la animación a partir del nombre
|
|
int getIndex(std::string name);
|
|
|
|
// Carga la animación desde un fichero
|
|
bool load(std::string filePath);
|
|
|
|
// Establece la animacion actual
|
|
void setCurrentAnimation(std::string name);
|
|
|
|
// Actualiza las variables del objeto
|
|
void update();
|
|
};
|
|
|
|
#endif |