aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mglpp/graphics/Sprite.hpp1
-rw-r--r--src/graphics/Sprite.cpp7
2 files changed, 8 insertions, 0 deletions
diff --git a/include/mglpp/graphics/Sprite.hpp b/include/mglpp/graphics/Sprite.hpp
index ec9f898..9453c30 100644
--- a/include/mglpp/graphics/Sprite.hpp
+++ b/include/mglpp/graphics/Sprite.hpp
@@ -22,6 +22,7 @@ namespace mgl {
vec2f get_position() const override;
void set_scale(vec2f scale);
void set_scale(float scale);
+ void set_size(vec2f size);
void set_rotation(float degrees);
void set_origin(vec2f origin);
diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp
index e6cef73..b94212e 100644
--- a/src/graphics/Sprite.cpp
+++ b/src/graphics/Sprite.cpp
@@ -42,6 +42,13 @@ namespace mgl {
sprite.scale = { scale, scale };
}
+ void Sprite::set_size(vec2f size) {
+ if(texture)
+ set_scale({ size.x / (float)texture->get_size().x, size.y / (float)texture->get_size().y });
+ else
+ set_scale({ 0.0f, 0.0f });
+ }
+
void Sprite::set_rotation(float degrees) {
mgl_sprite_set_rotation(&sprite, degrees);
}