From 8a5692c1a1292b966609e4b05773e2d567e7b9b6 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 23 Jun 2019 14:23:51 +0200 Subject: [PATCH] feat(assets): add a way to get current relative frame This function return the current frame relative to the first frame of the current animation --- CHANGELOG.md | 3 +++ gamecore/modules/assets/animator.lua | 4 ++++ gamecore/modules/assets/sprites.lua | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfdb3e..53471b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **actor2D:** Add multiple hitbox support. +- **assets:** Add a way to get current relative frame + + ### Changed - **world2D:** Use a list for bodies (hitboxes, etc) and one other for actors diff --git a/gamecore/modules/assets/animator.lua b/gamecore/modules/assets/animator.lua index 1498153..6aced5a 100644 --- a/gamecore/modules/assets/animator.lua +++ b/gamecore/modules/assets/animator.lua @@ -102,6 +102,10 @@ function Animator:getFrame() return self.frame end +function Animator:getRelativeFrame() + return self.frame - (self.animationData.startAt) + 1 +end + function Animator:animationExist(name) return (self.sprite.data.animations[self.currentAnimation] ~= nil) end diff --git a/gamecore/modules/assets/sprites.lua b/gamecore/modules/assets/sprites.lua index ddf4f89..63676a2 100644 --- a/gamecore/modules/assets/sprites.lua +++ b/gamecore/modules/assets/sprites.lua @@ -74,6 +74,10 @@ function Sprite:getDimensions() return self.tileset:getDimensions() end +function Sprite:getRelativeFrame() + return self.animator:getRelativeFrame() +end + -- DRAW FUNCTIONS -- Draw sprites using these functions