#include "AnimatedSprite.h"
#include <iostream>
AnimatedSprite::AnimatedSprite(const std::string& name) : rect({0, 0, 0, 0}), FPS(0), Frame(0), AmountOfFrames(0)
{
if(!texture.loadFromFile("res/temp_player.png") {}
sprite.setTexture(texture);
}
void AnimatedSprite::CreateAnimation(const sf::IntRect& Rect, const float& MilliSeconds, const int& frames)
{
rect = Rect;
FPS = MilliSeconds;
AmountOfFrames = frames;
}
sf::Sprite AnimatedSprite::play()
{
Frame += FPS;
if(Frame >= AmountOfFrames) {Frame = 0;}
sprite.setTextureRect({rect.left + (rect.width * (int)Frame), rect.top, rect.width, rect.height});
sprite.setOrigin(sprite.getLocalBounds().height / 2, sprite.getLocalBounds().width / 2);
return sprite;
}
void AnimatedSprite::SetPosition(const float& x, const float& y) { sprite.setPosition(x, y); }
void AnimatedSprite::Move(const float& x, const float& y) { sprite.move(x, y); }
void AnimatedSprite::SetRotation(const float& angle) { sprite.setRotation(angle); }
void AnimatedSprite::AddRotation(const float& angle) { sprite.rotate(angle); }
void AnimatedSprite::FlipH(const float& wayOfScale) { sprite.setScale(wayOfScale, sprite.getScale().y); }
void AnimatedSprite::FlipV(const float& wayOfScale) { sprite.setScale(sprite.getScale().x, wayOfScale); }
void AnimatedSprite::AddScale(const float& x, const float& y) { sprite.scale(x, y); }