Trabajando en la clase animatedsprite

This commit is contained in:
2022-08-12 13:55:56 +02:00
parent 71897291ff
commit 99005329de
2 changed files with 43 additions and 48 deletions

View File

@@ -1,6 +1,8 @@
#pragma once
#include <SDL2/SDL.h>
#include "movingsprite.h"
#include <vector>
#include <string>
#ifndef ANIMATEDSPRITE_H
#define ANIMATEDSPRITE_H
@@ -9,18 +11,17 @@
class AnimatedSprite : public MovingSprite
{
private:
struct sAnimation
struct t_animation
{
SDL_Rect frames[MAX_FRAMES]; // Cada uno de los frames que componen la animación
Uint8 numFrames; // Numero de frames que componen la animación
Uint8 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
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
};
sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las diferentes animaciones
Uint8 mCurrentFrame; // Frame actual
Uint16 mAnimationCounter; // Contador para las animaciones
std::vector<t_animation> animation; // Vector con las diferentes animaciones
public:
// Constructor
@@ -29,23 +30,20 @@ public:
// Destructor
~AnimatedSprite();
// Iniciador
void init();
// Calcula el frame correspondiente a la animación
void animate(int index);
void animate(std::string name);
// Establece el frame actual de la animación
void setCurrentFrame(Uint8 num);
void setCurrentFrame(std::string name, int num);
// Establece el valor del contador
void setAnimationCounter(Uint16 num);
void setAnimationCounter(std::string name, int num);
// Establece el rectangulo para un frame de una animación
void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h);
// Establece la velocidad de una animación
void setAnimationSpeed(Uint8 index, Uint8 speed);
void setAnimationSpeed(std::string name, int speed);
// Establece el numero de frames de una animación
void setAnimationNumFrames(Uint8 index, Uint8 num);
@@ -61,6 +59,9 @@ public:
// Devuelve el rectangulo de una animación y frame concreto
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
// Obtiene el indice de la animación a partir del nombre
int getIndex(std::string name);
};
#endif