updated animatedsprite.cpp
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
#ifndef ANIMATEDSPRITE_H
|
||||
#define ANIMATEDSPRITE_H
|
||||
|
||||
#define MAX_FRAMES 50
|
||||
#define MAX_ANIMATIONS 20
|
||||
|
||||
// Clase AnimatedSprite
|
||||
class AnimatedSprite : public MovingSprite
|
||||
{
|
||||
@@ -21,14 +24,20 @@ public:
|
||||
// Calcula el frame correspondiente a la animación
|
||||
void animate(int index);
|
||||
|
||||
// Actualiza todas las variables del objeto: posición, velocidad y animación
|
||||
void update();
|
||||
|
||||
// Establece el frame actual de la animación
|
||||
void setCurrentFrame(Uint8 num);
|
||||
void setCurrentFrame(Uint8 index, Uint8 num);
|
||||
|
||||
// Establece el valor del contador
|
||||
void setAnimationCounter(Uint16 num);
|
||||
void setAnimationCounter(Uint8 index, Uint16 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);
|
||||
void setAnimationFrames(Uint8 index, Uint8 frame, int x, int y, int w, int h);
|
||||
|
||||
// Establece el rectangulo para un frame de una animación
|
||||
void setAnimationFrames(Uint8 index, Uint8 frame, SDL_Rect rect);
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void setAnimationSpeed(Uint8 index, Uint8 speed);
|
||||
@@ -40,25 +49,27 @@ public:
|
||||
void setAnimationLoop(Uint8 index, bool loop);
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame);
|
||||
SDL_Rect getAnimationClip(Uint8 index, Uint8 frame);
|
||||
|
||||
// Establece la animación actual
|
||||
void AnimatedSprite::setCurrentAnimation(Uint8 index);
|
||||
|
||||
// Obtiene la animación actual
|
||||
Uint8 AnimatedSprite::getCurrentAnimation();
|
||||
|
||||
private:
|
||||
struct sAnimation
|
||||
{
|
||||
SDL_Rect frames[20]; // Hasta 20 frames
|
||||
Uint8 numFrames;
|
||||
Uint8 speed;
|
||||
bool loop;
|
||||
SDL_Rect frame[MAX_FRAMES]; // Vector con los rectangulos de cada frame de la animación
|
||||
Uint8 numFrames; // Cantidad de frames de la animacion
|
||||
Uint8 speed; // Velocidad de la animación
|
||||
Uint8 currentFrame; // Frame actual
|
||||
Uint16 counter; // Contador
|
||||
bool loop; // Indica si la animación se reproduce en bucle
|
||||
};
|
||||
|
||||
// Vector con las diferentes animaciones y los diferentes frames de cada animación
|
||||
sAnimation mAnimation[20]; // Hasta 20 animaciones
|
||||
|
||||
// Frame actual
|
||||
Uint8 mCurrentFrame;
|
||||
|
||||
// Contador para las animaciones
|
||||
Uint16 mAnimationCounter;
|
||||
sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las animaciones
|
||||
Uint8 mCurrentAnimation; // Animación actual;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user