aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Animator.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-04 10:56:53 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-04 10:56:53 +0100
commita11824956b478e356fa684c9d88b980aa22cb19a (patch)
treed743b0415040d68db4f5cf35b2fc58bab41f0e46 /src/crepe/api/Animator.cpp
parent683ae28b81a66f18bbadbe7ae70eb8ddd952c293 (diff)
implemented feedback, cameraValues need better name?
Diffstat (limited to 'src/crepe/api/Animator.cpp')
-rw-r--r--src/crepe/api/Animator.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp
index 1234967..dc99fd4 100644
--- a/src/crepe/api/Animator.cpp
+++ b/src/crepe/api/Animator.cpp
@@ -7,20 +7,23 @@
using namespace crepe;
-Animator::Animator(game_object_id_t id, const Animator::Data & ctx)
+Animator::Animator(uint32_t id, Sprite & ss, int max_row, int max_col,
+ const Animator::Data & ctx)
: Component(id),
+ spritesheet(ss),
+ row(max_row),
+ col(max_col),
data(ctx) {
dbg_trace();
- this->data.spritesheet.mask.h /= this->data.col;
- this->data.spritesheet.mask.w /= this->data.row;
- this->data.spritesheet.mask.x = 0;
- this->data.spritesheet.mask.y = this->data.col * this->data.spritesheet.mask.h;
+ this->spritesheet.mask.h /= this->col;
+ this->spritesheet.mask.w /= this->row;
+ this->spritesheet.mask.x = this->data.curr_row * this->spritesheet.mask.w;
+ this->spritesheet.mask.y = this->data.curr_col * this->spritesheet.mask.h;
// need to do this for to get the aspect ratio for a single clipping in the spritesheet
- Sprite & ss = this->data.spritesheet;
- ss.data.aspect_ratio
- = static_cast<double>(this->data.spritesheet.mask.w) / this->data.spritesheet.mask.h;
+ this->spritesheet.aspect_ratio
+ = static_cast<double>(this->spritesheet.mask.w) / this->spritesheet.mask.h;
}
Animator::~Animator() { dbg_trace(); }
@@ -43,12 +46,14 @@ void Animator::set_cycle_range(int start, int end) {
}
void Animator::set_anim(int col) {
- this->data.curr_row = 0;
- this->data.curr_col = col;
+ Animator::Data & ctx = this->data;
+ this->spritesheet.mask.x = ctx.curr_row = 0;
+ ctx.curr_col = col;
+ this->spritesheet.mask.y = ctx.curr_col * this->spritesheet.mask.h;
}
void Animator::next_anim() {
Animator::Data & ctx = this->data;
- ctx.curr_row = ctx.curr_row++ % ctx.row;
- ctx.spritesheet.mask.x = ctx.curr_row * ctx.spritesheet.mask.w;
+ ctx.curr_row = ctx.curr_row++ % this->row;
+ this->spritesheet.mask.x = ctx.curr_row * this->spritesheet.mask.w;
}