aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Sprite.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-28 13:01:07 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-28 13:01:14 +0100
commit63bce3dd21c82e2b4e45c07934d5a26684cdaa93 (patch)
treea46da0cb575fa21add7b07f2784c7889e4bc2771 /src/crepe/api/Sprite.h
parent2a2a3391ff0b449602825c3182af33c2ff52abc0 (diff)
parent85aa57e33d493502b05984ce44db6c68f627a6f2 (diff)
merge `master`
Diffstat (limited to 'src/crepe/api/Sprite.h')
-rw-r--r--src/crepe/api/Sprite.h64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 74a55d4..a0e90a0 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -1,6 +1,6 @@
#pragma once
-#include <memory>
+#include <cstdint>
#include "../Component.h"
@@ -9,18 +9,6 @@
namespace crepe {
-struct Rect {
- int w = 0;
- int h = 0;
- int x = 0;
- int y = 0;
-};
-
-struct FlipSettings {
- bool flip_x = false;
- bool flip_y = false;
-};
-
class SDLContext;
class Animator;
class AnimatorSystem;
@@ -34,6 +22,12 @@ class AnimatorSystem;
class Sprite : public Component {
public:
+ struct FlipSettings {
+ bool flip_x = false;
+ bool flip_y = false;
+ };
+
+public:
// TODO: Loek comment in github #27 will be looked another time
// about shared_ptr Texture
/**
@@ -42,9 +36,12 @@ public:
* \param image Shared pointer to the texture for this sprite.
* \param color Color tint applied to the sprite.
* \param flip Flip settings for horizontal and vertical orientation.
+ * \param order_layer decides the sorting in layer of the sprite.
+ * \param sort_layer decides the order in layer of the sprite.
+ * \param height the height of the image in game units
*/
- Sprite(game_object_id_t id, const std::shared_ptr<Texture> image, const Color & color,
- const FlipSettings & flip);
+ Sprite(game_object_id_t id, Texture & image, const Color & color,
+ const FlipSettings & flip, int sort_layer, int order_layer, int height);
/**
* \brief Destroys the Sprite instance.
@@ -52,38 +49,49 @@ public:
~Sprite();
//! Texture used for the sprite
- const std::shared_ptr<Texture> sprite_image;
+ const Texture sprite_image;
+
//! Color tint of the sprite
Color color;
+
//! Flip settings for the sprite
FlipSettings flip;
+
//! Layer sorting level of the sprite
- uint8_t sorting_in_layer = 0;
+ const int sorting_in_layer;
//! Order within the sorting layer
- uint8_t order_in_layer = 0;
+ const int order_in_layer;
+
+ //! height in world units
+ const int height;
-public:
/**
- * \brief Gets the maximum number of instances allowed for this sprite.
- * \return Maximum instance count as an integer.
+ * \aspect_ratio ratio of the img so that scaling will not become weird
*
- * For now is this number randomly picked. I think it will eventually be 1.
+ * cannot be const because if Animator component is addded then ratio becomes scuffed and
+ * does it need to be calculated again in the Animator
*/
- virtual int get_instances_max() const { return 10; }
+ double aspect_ratio;
private:
- //! Reads the sprite_rect of sprite
+ //! Reads the mask of sprite
friend class SDLContext;
- //! Reads the all the variables plus the sprite_rect
+ //! Reads the all the variables plus the mask
friend class Animator;
- //! Reads the all the variables plus the sprite_rect
+ //! Reads the all the variables plus the mask
friend class AnimatorSystem;
+ struct Rect {
+ int w = 0;
+ int h = 0;
+ int x = 0;
+ int y = 0;
+ };
//! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator
- // object is present in GameObject
- Rect sprite_rect;
+ // object is present in GameObject. this is in sprite pixels
+ Rect mask;
};
} // namespace crepe