#include "AnimatedSprite.hpp" #include "GameData.hpp" #include #include #include AnimatedSprite::AnimatedSprite(const std::vector &texture_paths) : sf::Sprite(PLACE_HOLDER_TEXTURE) { frames_textures.reserve(texture_paths.size()); for (const auto &path : texture_paths) { auto new_texture = sf::Texture(); if (!new_texture.loadFromFile(path)) { printf("failed to load a texture of AnimatedSprite"); exit(0); }; frames_textures.push_back(std::move(new_texture)); } assert(frames_textures.size() > 0); // setTexture is frome Sprite setTexture(frames_textures[0]); }; void AnimatedSprite::update(float dtime) { time_without_change += dtime; if (time_without_change > time_beetwen_frames) { current_frame = (current_frame + 1) % frames_textures.size(); time_without_change = 0.0; setTexture(frames_textures[current_frame]); } }