From 3e79bcb62d7896d65da1f546d985d46943a572a9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 2 Sep 2022 14:00:08 +0200 Subject: [PATCH] =?UTF-8?q?Peque=C3=B1as=20optimizaciones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/animatedsprite.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/animatedsprite.cpp b/source/animatedsprite.cpp index 562614d..dc5d18b 100644 --- a/source/animatedsprite.cpp +++ b/source/animatedsprite.cpp @@ -29,20 +29,26 @@ AnimatedSprite::~AnimatedSprite() int AnimatedSprite::getIndex(std::string name) { int index = -1; - for (int i = 0; i < animation.size(); i++) + /*for (int i = 0; i < (int)animation.size(); i++) { if (animation[i].name == name) { index = i; } + }*/ + for (auto a : animation) + { + index++; + if (a.name == name) + { + return index; + } } - if (index == -1) - { - printf("** Warning: could not find \"%s\" animation\n", name.c_str()); - index = 0; - } - return index; + printf("** Warning: could not find \"%s\" animation\n", name.c_str()); + index = 0; + + return -1; } // Calcula el frame correspondiente a la animación