.
This commit is contained in:
@@ -56,12 +56,6 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture)
|
||||
: MovingSprite(texture),
|
||||
current_animation_(0) {}
|
||||
|
||||
// Destructor
|
||||
AnimatedSprite::~AnimatedSprite()
|
||||
{
|
||||
animations_.clear();
|
||||
}
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(const std::string &name)
|
||||
{
|
||||
@@ -260,8 +254,8 @@ std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path
|
||||
{
|
||||
// Inicializa variables
|
||||
std::vector<Animation> animations;
|
||||
auto frame_width = 0;
|
||||
auto frame_height = 0;
|
||||
auto frame_width = 1;
|
||||
auto frame_height = 1;
|
||||
|
||||
std::ifstream file(file_path);
|
||||
std::string line;
|
||||
@@ -273,8 +267,8 @@ std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path
|
||||
std::cout << "Animation loaded: " << getFileName(file_path) << std::endl;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
auto max_tiles = 0;
|
||||
auto frames_per_row = 0;
|
||||
auto max_tiles = 1;
|
||||
auto frames_per_row = 1;
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]")
|
||||
{
|
||||
@@ -333,20 +327,15 @@ std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path
|
||||
}
|
||||
|
||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
||||
else
|
||||
if (line != "[animation]")
|
||||
{
|
||||
// Encuentra la posición del caracter '='
|
||||
int pos = line.find("=");
|
||||
size_t pos = line.find("=");
|
||||
|
||||
// Procesa las dos subcadenas
|
||||
if (pos != (int)line.npos)
|
||||
if (pos != line.npos)
|
||||
{
|
||||
if (line.substr(0, pos) == "frames_per_row")
|
||||
{
|
||||
frames_per_row = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
|
||||
else if (line.substr(0, pos) == "frame_width")
|
||||
if (line.substr(0, pos) == "frame_width")
|
||||
{
|
||||
frame_width = std::stoi(line.substr(pos + 1, line.length()));
|
||||
}
|
||||
@@ -358,21 +347,14 @@ std::vector<Animation> AnimatedSprite::loadFromFile(const std::string &file_path
|
||||
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: file " << getFileName(file_path).c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << getFileName(file_path) << "\n, unknown parameter \"" << line.substr(0, pos) << "\"" << std::endl;
|
||||
}
|
||||
|
||||
// Normaliza valores
|
||||
if (frames_per_row == 0 && frame_width > 0)
|
||||
{
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
}
|
||||
frames_per_row = texture_->getWidth() / frame_width;
|
||||
|
||||
if (max_tiles == 0 && frame_width > 0 && frame_height > 0)
|
||||
{
|
||||
const auto w = texture_->getWidth() / frame_width;
|
||||
const auto h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
const auto w = texture_->getWidth() / frame_width;
|
||||
const auto h = texture_->getHeight() / frame_height;
|
||||
max_tiles = w * h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user