feat(actors): add animation callback

This commit is contained in:
Kazhnuz 2019-07-29 09:02:00 +02:00
parent 88e4d2c36a
commit 791bf8754e
2 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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)