Trabajando en la reescritura del código

This commit is contained in:
2022-09-26 14:06:44 +02:00
parent 837bcbd1da
commit b092d3f86a
10 changed files with 244 additions and 210 deletions

View File

@@ -103,30 +103,42 @@ void AnimatedSprite::setAnimationCounter(std::string name, int num)
animation[getIndex(name)].counter = num;
}
// Establece el valor del contador
void AnimatedSprite::setAnimationCounter(int index, int num)
{
animation[index].counter = num;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(std::string name, int speed)
{
animation[getIndex(name)].counter = speed;
}
// Establece la velocidad de una animación
void AnimatedSprite::setAnimationSpeed(int index, int speed)
{
animation[index].counter = speed;
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(std::string name, int loop)
{
animation[getIndex(name)].loop = loop;
}
// Establece si la animación se reproduce en bucle
void AnimatedSprite::setAnimationLoop(int index, int loop)
{
animation[index].loop = loop;
}
// Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(std::string name, bool value)
{
animation[getIndex(name)].completed = value;
}
// OLD - Establece el valor de la variable
void AnimatedSprite::setAnimationCompleted(int index, bool value)
{
animation[index].completed = value;
}
// Comprueba si ha terminado la animación
bool AnimatedSprite::animationIsCompleted()
{
@@ -285,6 +297,19 @@ void AnimatedSprite::setCurrentAnimation(std::string name)
}
}
// Establece la animacion actual
void AnimatedSprite::setCurrentAnimation(int index)
{
const int newAnimation = index;
if (currentAnimation != newAnimation)
{
currentAnimation = newAnimation;
animation[currentAnimation].currentFrame = 0;
animation[currentAnimation].counter = 0;
animation[currentAnimation].completed = false;
}
}
// Actualiza las variables del objeto
void AnimatedSprite::update()
{
@@ -295,14 +320,14 @@ void AnimatedSprite::update()
// Establece el rectangulo para un frame de una animación
void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h)
{
animation[index_animation].frames[index_frame].x = x;
animation[index_animation].frames[index_frame].y = y;
animation[index_animation].frames[index_frame].w = w;
animation[index_animation].frames[index_frame].h = h;
animation[index_animation].frames.push_back({x, y, w, h});
}
// Establece el numero de frames de una animación
void AnimatedSprite::setAnimationNumFrames(Uint8 index, Uint8 num)
// OLD - Establece el contador para todas las animaciones
void AnimatedSprite::setAnimationCounter(int value)
{
animation[index].numFrames = num;
for (auto &a:animation)
{
a.counter = value;
}
}