aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Sprite.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-07 14:53:01 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-07 14:53:01 +0100
commit5c3ce63558f2d5dec06a124773f910d783bb22aa (patch)
tree77402408eaba5dab3fb5064628dad1a5fd2be0f1 /src/crepe/api/Sprite.h
parent1e9e564f3806d07c7b0dc445c4ae2e738350fc83 (diff)
parentfdb4c99e139a264d4e15e6913a3756fc6cccb2f2 (diff)
merge master
Diffstat (limited to 'src/crepe/api/Sprite.h')
-rw-r--r--src/crepe/api/Sprite.h92
1 files changed, 55 insertions, 37 deletions
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index a0e90a0..dbf41e4 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -1,11 +1,10 @@
#pragma once
-#include <cstdint>
-
#include "../Component.h"
#include "Color.h"
#include "Texture.h"
+#include "types.h"
namespace crepe {
@@ -20,60 +19,79 @@ class AnimatorSystem;
* flip settings, and is managed in layers with defined sorting orders.
*/
class Sprite : public Component {
-
public:
+ //! settings to flip the image
struct FlipSettings {
+ //! horizantal flip
bool flip_x = false;
+ //! vertical flip
bool flip_y = false;
};
+ //! Sprite data that does not have to be set in the constructor
+ struct Data {
+ /**
+ * \brief Sprite tint (multiplied)
+ *
+ * The sprite texture's pixels are multiplied by this color before being displayed
+ * (including alpha channel for transparency).
+ */
+ Color color = Color::WHITE;
+
+ //! Flip settings for the sprite
+ FlipSettings flip;
+
+ //! Layer sorting level of the sprite
+ const int sorting_in_layer = 0;
+
+ //! Order within the sorting layer
+ const int order_in_layer = 0;
+
+ /**
+ * \brief width and height of the sprite in game units
+ *
+ * - if exclusively width is specified, the height is calculated using the texture's aspect
+ * ratio
+ * - if exclusively height is specified, the width is calculated using the texture's aspect
+ * ratio
+ * - if both are specified the texture is streched to fit the specified size
+ */
+ vec2 size = {0, 0};
+
+ //! independent sprite angle. rotating clockwise direction in degrees
+ float angle_offset = 0;
+
+ //! independent sprite scale multiplier
+ float scale_offset = 1;
+
+ //! independent sprite offset position
+ vec2 position_offset;
+ };
+
public:
- // TODO: Loek comment in github #27 will be looked another time
- // about shared_ptr Texture
/**
- * \brief Constructs a Sprite with specified parameters.
* \param game_id Unique identifier for the game object this sprite belongs to.
- * \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, Texture & image, const Color & color,
- const FlipSettings & flip, int sort_layer, int order_layer, int height);
-
- /**
- * \brief Destroys the Sprite instance.
+ * \param texture asset of the image
+ * \param ctx all the sprite data
*/
+ Sprite(game_object_id_t id, Texture & texture, const Data & data);
~Sprite();
//! Texture used for the sprite
- const Texture sprite_image;
-
- //! Color tint of the sprite
- Color color;
-
- //! Flip settings for the sprite
- FlipSettings flip;
+ const Texture texture;
- //! Layer sorting level of the sprite
- const int sorting_in_layer;
- //! Order within the sorting layer
- const int order_in_layer;
-
- //! height in world units
- const int height;
+ Data data;
+private:
/**
- * \aspect_ratio ratio of the img so that scaling will not become weird
+ * \brief ratio of the img
*
- * cannot be const because if Animator component is addded then ratio becomes scuffed and
- * does it need to be calculated again in the Animator
+ * - This will multiply one of \c size variable if it is 0.
+ * - Will be adjusted if \c Animator component is added to an GameObject that is why this
+ * value cannot be const.
*/
- double aspect_ratio;
+ float aspect_ratio;
-private:
//! Reads the mask of sprite
friend class SDLContext;