diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-12-02 11:48:06 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-12-02 11:48:06 +0100 |
commit | e72c8d1bbd0d74dcf4a4832d0352f5f8211fc343 (patch) | |
tree | b0cbcc55d57df837c2e0607681eddf2312d1fa7f | |
parent | 0108af496da089dbee70ce80d778dfb5c238460b (diff) |
Sprite: add get_size, which returns the texture size and takes into account scaling
-rw-r--r-- | include/mglpp/graphics/Sprite.hpp | 2 | ||||
-rw-r--r-- | src/graphics/Sprite.cpp | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/include/mglpp/graphics/Sprite.hpp b/include/mglpp/graphics/Sprite.hpp index 9453c30..21b2a41 100644 --- a/include/mglpp/graphics/Sprite.hpp +++ b/include/mglpp/graphics/Sprite.hpp @@ -20,6 +20,8 @@ namespace mgl { void set_position(vec2f position) override; void set_color(Color color) override; vec2f get_position() const override; + vec2f get_size() const; + void set_scale(vec2f scale); void set_scale(float scale); void set_size(vec2f size); diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index b94212e..461b14c 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -34,6 +34,13 @@ namespace mgl { return { sprite.position.x, sprite.position.y }; } + vec2f Sprite::get_size() const { + if(texture) + return get_scale() * mgl::vec2f(texture->get_size().x, texture->get_size().y); + else + return { 0.0f, 0.0f }; + } + void Sprite::set_scale(vec2f scale) { sprite.scale = { scale.x, scale.y }; } |