feat: handle changing animations speed
This commit is contained in:
parent
3b53d62ca1
commit
07fc1efc8a
2 changed files with 10 additions and 1 deletions
|
@ -35,6 +35,7 @@ function Animator:new(sprite)
|
|||
self.animationData = {}
|
||||
|
||||
self.customSpeed = 0
|
||||
self.speedFactor = 1
|
||||
|
||||
self:changeToDefaultAnimation()
|
||||
end
|
||||
|
@ -43,6 +44,10 @@ function Animator:setCustomSpeed(customSpeed)
|
|||
self.customSpeed = customSpeed or 0
|
||||
end
|
||||
|
||||
function Animator:setSpeedFactor(speedFactor)
|
||||
self.speedFactor = speedFactor or 1
|
||||
end
|
||||
|
||||
-- UPDATE FUNCTIONS
|
||||
-- Update the animation of the animator
|
||||
|
||||
|
@ -56,7 +61,7 @@ function Animator:update(dt)
|
|||
if (self.animationData.speed) == -1 then
|
||||
speed = self.customSpeed --math.abs(self.xsp / 16)
|
||||
end
|
||||
self.frameTimer = self.frameTimer + (speed * dt)
|
||||
self.frameTimer = self.frameTimer + (speed * dt * self.speedFactor)
|
||||
if self.frameTimer > 1 then
|
||||
self.frameTimer = 0
|
||||
if self.frame == self.animationData.endAt then
|
||||
|
|
|
@ -63,6 +63,10 @@ function Sprite:changeAnimation(name, restart)
|
|||
self.animator:changeAnimation(name, restart)
|
||||
end
|
||||
|
||||
function Sprite:setSpeedFactor(speedFactor)
|
||||
self.animator:setSpeedFactor(speedFactor)
|
||||
end
|
||||
|
||||
-- INFO FUNCTIONS
|
||||
-- get information with these functions
|
||||
|
||||
|
|
Loading…
Reference in a new issue