From 791bf8754e5e9a43d2d863fa185e4dd73336c66e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 29 Jul 2019 09:02:00 +0200 Subject: [PATCH] feat(actors): add animation callback --- .../core/modules/assets/animator.lua | 14 ++++++++++++++ .../core/modules/world/actors/baseactor.lua | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/sonic-radiance.love/core/modules/assets/animator.lua b/sonic-radiance.love/core/modules/assets/animator.lua index 53da4e4..9d830a1 100644 --- a/sonic-radiance.love/core/modules/assets/animator.lua +++ b/sonic-radiance.love/core/modules/assets/animator.lua @@ -63,6 +63,7 @@ function Animator:update(dt) if not (self.animationData.pauseAtEnd) then self.frame = self.animationData.loop end + self:sendCallback() else self.frame = self.frame + 1 end @@ -120,6 +121,19 @@ function Animator:getDimensions() return self.sprite:getDimensions() end +-- CALLBACK FUNCTIONS +-- Handle getting a calback from the animation system + +function Animator:setCallback(actor) + self.actor = actor +end + +function Animator:sendCallback() + if (self.actor ~= nil) then + self.actor:animationEnded(self.currentAnimation) + end +end + -- DRAW FUNCTIONS -- Draw animations using these functions diff --git a/sonic-radiance.love/core/modules/world/actors/baseactor.lua b/sonic-radiance.love/core/modules/world/actors/baseactor.lua index 190747a..7b82f46 100644 --- a/sonic-radiance.love/core/modules/world/actors/baseactor.lua +++ b/sonic-radiance.love/core/modules/world/actors/baseactor.lua @@ -378,6 +378,7 @@ end function BaseActor:cloneSprite() if self.sprite.name ~= nil then self.sprite.clone = self.assets.sprites[self.sprite.name]:clone() + self.sprite.clone:setCallback(self) end end @@ -389,6 +390,10 @@ function BaseActor:changeAnimation(animation, restart) end end +function BaseActor:animationEnded(animation) + -- Empty placeholder function +end + function BaseActor:setCustomSpeed(customSpeed) if (self.sprite.clone == nil) then self.assets.sprites[self.sprite.name]:setCustomSpeed(customSpeed)