11#ifndef SFMLSPRITE_HPP_
12#define SFMLSPRITE_HPP_
15#include <SFML/Graphics.hpp>
36 return _texture.isReady();
40 sf::FloatRect rect = _sprite.getGlobalBounds();
41 return {rect.position.x, rect.position.y, rect.size.x, rect.size.y};
45 _sprite.setTextureRect(sf::IntRect{
46 sf::Vector2i{
static_cast<int32_t
>(rect.
x),
static_cast<int32_t
>(rect.
y)},
47 sf::Vector2i{
static_cast<int32_t
>(rect.
w),
static_cast<int32_t
>(rect.
h)}});
51 sf::Vector2f pos = _sprite.getPosition();
52 return {
static_cast<double>(pos.x),
static_cast<double>(pos.y)};
55 _sprite.setPosition({
static_cast<float>(position.
x),
static_cast<float>(position.
y)});
59 return _sprite.getRotation().asDegrees();
64 _sprite.setRotation(sf::radians(angle));
66 _sprite.setRotation(sf::degrees(angle));
70 sf::Vector2f scale = _sprite.getScale();
71 sf::Vector2f size = _sprite.getLocalBounds().size;
72 return {
static_cast<double>(size.x * scale.x),
static_cast<double>(size.y * scale.y)};
76 sf::Vector2f bounds = _sprite.getLocalBounds().size;
77 if (bounds.x == 0 || bounds.y == 0)
return;
79 static_cast<float>(size.
x / bounds.x),
80 static_cast<float>(size.
y / bounds.y)
void setPosition(Vector2f position) override
Set the Position object.
Definition SfmlSprite.hpp:54
Rect< float > getBounds() const override
give the bounds of the sprite
Definition SfmlSprite.hpp:39
~SfmlSprite() override=default
SfmlSprite(SfmlTexture &texture)
Definition SfmlSprite.hpp:30
bool isReady() const override
notice if the sprite is ready
Definition SfmlSprite.hpp:35
Vector2f getPosition() const override
Get the Position object.
Definition SfmlSprite.hpp:50
float getRotation() const override
Get the Rotation object.
Definition SfmlSprite.hpp:58
void setRotation(float angle, bool isRad=false) override
Set the Rotation object.
Definition SfmlSprite.hpp:62
friend class SfmlWindow
Definition SfmlSprite.hpp:84
void setSize(Vector2f size) override
Set the Sprite size.
Definition SfmlSprite.hpp:75
Vector2f getSize() const override
Get the Sprite size.
Definition SfmlSprite.hpp:69
void setCrop(Rect< float > rect) override
Crop the sprite with a rectangle.
Definition SfmlSprite.hpp:44
Sfml Texture class - owns the loaded texture. SfmlSprite only references it (sf::Sprite itself alread...
Definition SfmlTexture.hpp:28
Sprite interface.
Definition ISprite.hpp:22
Vector2< double > Vector2f
Definition Vector2.hpp:112
T w
Definition Shape.hpp:33
T h
Definition Shape.hpp:33
T y
Definition Shape.hpp:33
T x
Definition Shape.hpp:33
T y
Definition Vector2.hpp:21
T x
Definition Vector2.hpp:21