Revisada la carrega de recursos en game.cpp
This commit is contained in:
@@ -16,18 +16,16 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::stri
|
||||
{
|
||||
animations_ = loadFromFile(file_path);
|
||||
}
|
||||
//setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
}
|
||||
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, std::vector<std::string> *animations)
|
||||
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::vector<std::string> &animations)
|
||||
: MovingSprite(texture),
|
||||
current_animation_(0)
|
||||
{
|
||||
if (animations)
|
||||
if (!animations.empty())
|
||||
{
|
||||
loadFromVector(animations);
|
||||
}
|
||||
//setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
|
||||
}
|
||||
|
||||
// Constructor
|
||||
@@ -179,7 +177,7 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF)
|
||||
}
|
||||
|
||||
// Carga la animación desde un vector
|
||||
bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
bool AnimatedSprite::loadFromVector(const std::vector<std::string> &source)
|
||||
{
|
||||
// Inicializa variables
|
||||
auto frames_per_row = 0;
|
||||
@@ -193,10 +191,10 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
|
||||
// Recorre todo el vector
|
||||
auto index = 0;
|
||||
while (index < (int)source->size())
|
||||
while (index < (int)source.size())
|
||||
{
|
||||
// Lee desde el vector
|
||||
line = source->at(index);
|
||||
line = source.at(index);
|
||||
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
@@ -214,7 +212,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
|
||||
{
|
||||
// Aumenta el indice para leer la siguiente linea
|
||||
index++;
|
||||
line = source->at(index);
|
||||
line = source.at(index);
|
||||
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
@@ -378,7 +376,7 @@ void AnimatedSprite::resetAnimation()
|
||||
}
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
std::vector<Animation> AnimatedSprite::loadFromFile(std::string file_path)
|
||||
std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path)
|
||||
{
|
||||
// Inicializa variables
|
||||
std::vector<Animation> animations;
|
||||
|
||||
Reference in New Issue
Block a user