feat(actors): add animation callback
This commit is contained in:
parent
88e4d2c36a
commit
791bf8754e
2 changed files with 19 additions and 0 deletions
|
@ -63,6 +63,7 @@ function Animator:update(dt)
|
||||||
if not (self.animationData.pauseAtEnd) then
|
if not (self.animationData.pauseAtEnd) then
|
||||||
self.frame = self.animationData.loop
|
self.frame = self.animationData.loop
|
||||||
end
|
end
|
||||||
|
self:sendCallback()
|
||||||
else
|
else
|
||||||
self.frame = self.frame + 1
|
self.frame = self.frame + 1
|
||||||
end
|
end
|
||||||
|
@ -120,6 +121,19 @@ function Animator:getDimensions()
|
||||||
return self.sprite:getDimensions()
|
return self.sprite:getDimensions()
|
||||||
end
|
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 FUNCTIONS
|
||||||
-- Draw animations using these functions
|
-- Draw animations using these functions
|
||||||
|
|
||||||
|
|
|
@ -378,6 +378,7 @@ end
|
||||||
function BaseActor:cloneSprite()
|
function BaseActor:cloneSprite()
|
||||||
if self.sprite.name ~= nil then
|
if self.sprite.name ~= nil then
|
||||||
self.sprite.clone = self.assets.sprites[self.sprite.name]:clone()
|
self.sprite.clone = self.assets.sprites[self.sprite.name]:clone()
|
||||||
|
self.sprite.clone:setCallback(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -389,6 +390,10 @@ function BaseActor:changeAnimation(animation, restart)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BaseActor:animationEnded(animation)
|
||||||
|
-- Empty placeholder function
|
||||||
|
end
|
||||||
|
|
||||||
function BaseActor:setCustomSpeed(customSpeed)
|
function BaseActor:setCustomSpeed(customSpeed)
|
||||||
if (self.sprite.clone == nil) then
|
if (self.sprite.clone == nil) then
|
||||||
self.assets.sprites[self.sprite.name]:setCustomSpeed(customSpeed)
|
self.assets.sprites[self.sprite.name]:setCustomSpeed(customSpeed)
|
||||||
|
|
Loading…
Reference in a new issue