initial commit
This commit is contained in:
65
animatedsprite.hpp
Normal file
65
animatedsprite.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Animation
|
||||
{
|
||||
struct Animation
|
||||
{
|
||||
sf::Vector2u frameOrigin; // offset in pixels
|
||||
sf::Vector2u frameSize; // in pixels
|
||||
sf::Vector2u frameStep; // in pixels
|
||||
sf::Vector2u frameMargin; // in pixels
|
||||
unsigned frameCount;
|
||||
unsigned frameTime; // in milliseconds
|
||||
bool reverse;
|
||||
bool loop;
|
||||
bool bounce;
|
||||
|
||||
sf::IntRect GetFrame(unsigned const frameNumber, bool const bounced = false) const;
|
||||
|
||||
Animation();
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, Animation> LoadFromFile(std::string const & filepath);
|
||||
|
||||
class Sprite : public sf::Sprite
|
||||
{
|
||||
protected:
|
||||
std::unordered_map<std::string, Animation> const & animations;
|
||||
Animation const * currentAnimation;
|
||||
|
||||
unsigned currentFrame;
|
||||
unsigned currentFrameTime;
|
||||
bool bouncing;
|
||||
bool isFlippedHorizontally;
|
||||
bool isFlippedVertically;
|
||||
|
||||
void SetFrame();
|
||||
|
||||
public:
|
||||
virtual bool IsAnimationFinished() const;
|
||||
|
||||
// This flip call is not free, so be careful with lots
|
||||
// of repeated calls to this function
|
||||
virtual void SetHorizontalFlip(bool const v);
|
||||
// This flip call is not free, so be careful with lots
|
||||
// of repeated calls to this function
|
||||
virtual void SetVerticalFlip(bool const v);
|
||||
|
||||
bool IsFlippedHorizontally() const;
|
||||
bool IsFlippedVertically() const;
|
||||
|
||||
void ResetAnimation();
|
||||
bool SetAnimation(const std::string & name);
|
||||
|
||||
virtual void Update(sf::Time const & elapsed);
|
||||
void UpdateFromOther(Sprite const & other);
|
||||
|
||||
Sprite(std::unordered_map<std::string, Animation> const & _animations,
|
||||
std::string const & animation,
|
||||
sf::Texture const & texture);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user