aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Animator.cpp
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-14 11:40:33 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-14 11:40:33 +0100
commit061b2b8ab9aba67c1467cdd163fb7a04de95f4f1 (patch)
treee1960a83461e0d83a7027a88404af1a7c70f6dcd /src/crepe/api/Animator.cpp
parentfd2ebb54d0c2b269c15fc84a4ac77993efc917d7 (diff)
parentb9fc66f6922b1f40f2dbe14e8dfc4caa469654bc (diff)
Merge branch 'master' of github.com:lonkaars/crepe into jaro/collision-system
Diffstat (limited to 'src/crepe/api/Animator.cpp')
-rw-r--r--src/crepe/api/Animator.cpp50
1 files changed, 40 insertions, 10 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 45f67f6..4ce4bf0 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -7,21 +7,51 @@
using namespace crepe;
-Animator::Animator(game_object_id_t id, Sprite & ss, int row, int col, int col_animator)
+Animator::Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size,
+ const uvec2 & grid_size, const Animator::Data & data)
: Component(id),
- spritesheet(ss),
- row(row),
- col(col) {
+ spritesheet(spritesheet),
+ grid_size(grid_size),
+ data(data) {
dbg_trace();
- this->spritesheet.mask.h /= col;
- this->spritesheet.mask.w /= row;
+ this->spritesheet.mask.w = single_frame_size.x;
+ this->spritesheet.mask.h = single_frame_size.y;
this->spritesheet.mask.x = 0;
- this->spritesheet.mask.y = col_animator * this->spritesheet.mask.h;
- this->active = false;
+ this->spritesheet.mask.y = 0;
- // need to do this for to get the aspect ratio for a single clipping in the spritesheet
this->spritesheet.aspect_ratio
- = static_cast<double>(this->spritesheet.mask.w) / this->spritesheet.mask.h;
+ = static_cast<float>(single_frame_size.x) / single_frame_size.y;
}
+
Animator::~Animator() { dbg_trace(); }
+
+void Animator::loop() { this->data.looping = true; }
+
+void Animator::play() { this->active = true; }
+
+void Animator::pause() { this->active = false; }
+
+void Animator::stop() {
+ this->active = false;
+ this->data.col = 0;
+ this->data.row = 0;
+}
+void Animator::set_fps(int fps) { this->data.fps = fps; }
+
+void Animator::set_cycle_range(int start, int end) {
+ this->data.cycle_start = start, this->data.cycle_end = end;
+}
+
+void Animator::set_anim(int col) {
+ Animator::Data & ctx = this->data;
+ this->spritesheet.mask.x = ctx.row = 0;
+ ctx.col = col;
+ this->spritesheet.mask.y = ctx.col * this->spritesheet.mask.h;
+}
+
+void Animator::next_anim() {
+ Animator::Data & ctx = this->data;
+ ctx.row = ctx.row++ % this->grid_size.x;
+ this->spritesheet.mask.x = ctx.row * this->spritesheet.mask.w;
+}