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.animationData = {}
|
||||||
|
|
||||||
self.customSpeed = 0
|
self.customSpeed = 0
|
||||||
|
self.speedFactor = 1
|
||||||
|
|
||||||
self:changeToDefaultAnimation()
|
self:changeToDefaultAnimation()
|
||||||
end
|
end
|
||||||
|
@ -43,6 +44,10 @@ function Animator:setCustomSpeed(customSpeed)
|
||||||
self.customSpeed = customSpeed or 0
|
self.customSpeed = customSpeed or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Animator:setSpeedFactor(speedFactor)
|
||||||
|
self.speedFactor = speedFactor or 1
|
||||||
|
end
|
||||||
|
|
||||||
-- UPDATE FUNCTIONS
|
-- UPDATE FUNCTIONS
|
||||||
-- Update the animation of the animator
|
-- Update the animation of the animator
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ function Animator:update(dt)
|
||||||
if (self.animationData.speed) == -1 then
|
if (self.animationData.speed) == -1 then
|
||||||
speed = self.customSpeed --math.abs(self.xsp / 16)
|
speed = self.customSpeed --math.abs(self.xsp / 16)
|
||||||
end
|
end
|
||||||
self.frameTimer = self.frameTimer + (speed * dt)
|
self.frameTimer = self.frameTimer + (speed * dt * self.speedFactor)
|
||||||
if self.frameTimer > 1 then
|
if self.frameTimer > 1 then
|
||||||
self.frameTimer = 0
|
self.frameTimer = 0
|
||||||
if self.frame == self.animationData.endAt then
|
if self.frame == self.animationData.endAt then
|
||||||
|
|
|
@ -63,6 +63,10 @@ function Sprite:changeAnimation(name, restart)
|
||||||
self.animator:changeAnimation(name, restart)
|
self.animator:changeAnimation(name, restart)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Sprite:setSpeedFactor(speedFactor)
|
||||||
|
self.animator:setSpeedFactor(speedFactor)
|
||||||
|
end
|
||||||
|
|
||||||
-- INFO FUNCTIONS
|
-- INFO FUNCTIONS
|
||||||
-- get information with these functions
|
-- get information with these functions
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue