aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Animator.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-06 19:26:27 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-06 19:26:27 +0100
commite8d9e38b4c265e0efde32c38d01b511cb572a34d (patch)
tree0af9b8f5e7c9e59de2e3c9ebc175ce31e9a86c20 /src/crepe/api/Animator.h
parentcfd578dd0b7d5894ff0b0a0796d85cd5e9ae6e56 (diff)
parentf3adf300c5ba9b382f74e5b704501fd047399062 (diff)
Merge branch 'niels/decoupling_pixel_and_pos' of github.com:lonkaars/crepe
Diffstat (limited to 'src/crepe/api/Animator.h')
-rw-r--r--src/crepe/api/Animator.h118
1 files changed, 91 insertions, 27 deletions
diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h
index 6c506aa..23d29f6 100644
--- a/src/crepe/api/Animator.h
+++ b/src/crepe/api/Animator.h
@@ -1,7 +1,10 @@
#pragma once
+#include <sys/types.h>
+
#include "Component.h"
#include "Sprite.h"
+#include "types.h"
namespace crepe {
@@ -16,56 +19,117 @@ class SDLContext;
* sheet. It can be used to play animations, loop them, or stop them.
*/
class Animator : public Component {
+public:
+ struct Data {
+
+ //! frames per second for animation
+ unsigned int fps = 1;
+
+ //! The current col being animated.
+ unsigned int col = 0;
+
+ //! The current row being animated.
+ unsigned int row = 0;
+
+ //! should the animation loop
+ bool looping = false;
+
+ //! starting frame for cycling
+ unsigned int cycle_start = 0;
+
+ //! end frame for cycling (-1 --> use last frame)
+ int cycle_end = -1;
+
+ //! offset in pixels.
+ // TODO implement
+ unsigned int white_space = 0;
+ };
public:
- //TODO: need to implement this
+ /**
+ * \brief Animator will repeat the animation
+ *
+ */
void loop();
+
+ /**
+ * \brief starts the animation
+ *
+ */
+ void play();
+ /**
+ * \brief pauses the animation
+ *
+ * sets the active false
+ *
+ */
+ void pause();
+
+ /**
+ * \brief stops the animation
+ *
+ * sets the active on false and resets all the current rows and columns
+ *
+ */
void stop();
+ /**
+ * \brief set frames per second
+ *
+ * \param fps frames per second
+ */
+ void set_fps(int fps);
+ /**
+ * \brief set the range in the row
+ *
+ * \param start of row animation
+ * \param end of row animation
+ */
+ void set_cycle_range(int start, int end);
+ /**
+ * \brief select which column to animate from
+ *
+ * \param col animation column
+ */
+ void set_anim(int col);
+
+ /**
+ * \brief will go to the next animaiton of current row
+ *
+ */
+ void next_anim();
public:
/**
* \brief Constructs an Animator object that will control animations for a sprite sheet.
*
* \param id The unique identifier for the component, typically assigned automatically.
- * \param spritesheet A reference to the Sprite object which holds the sprite sheet for
- * animation.
- * \param row The maximum number of rows in the sprite sheet.
- * \param col The maximum number of columns in the sprite sheet.
- * \param col_animate The specific col index of the sprite sheet to animate. This allows
- * selecting which col to animate from multiple col in the sheet.
+ * \param ss the reference to the spritesheet
+ * \param max_row maximum of rows inside the given spritesheet
+ * \param max_col maximum of columns inside the given spritesheet
+ * \param data extra animation data for more control
*
* This constructor sets up the Animator with the given parameters, and initializes the
* animation system.
*/
- Animator(uint32_t id, Sprite & spritesheet, int row, int col, int col_animate);
-
+ Animator(game_object_id_t id, Sprite & ss, unsigned int max_row, unsigned int max_col,
+ const Animator::Data & data);
~Animator(); // dbg_trace
-private:
- //! A reference to the Sprite sheet containing the animation frames.
- Sprite & spritesheet;
-
+public:
//! The maximum number of columns in the sprite sheet.
- const int col;
+ const unsigned int max_columns;
//! The maximum number of rows in the sprite sheet.
- const int row;
-
- //! The current col being animated.
- int curr_col = 0;
+ const unsigned int max_rows;
- //! The current row being animated.
- int curr_row = 0;
-
- //TODO: Is this necessary?
- //int fps;
+ Animator::Data data;
private:
- //! AnimatorSystem adjust the private member parameters of Animator;
- friend class AnimatorSystem;
+ //! A reference to the Sprite sheet containing.
+ Sprite & spritesheet;
- //! SDLContext reads the Animator member var's
- friend class SDLContext;
+ // uses the spritesheet
+ friend AnimatorSystem;
};
} // namespace crepe
//