37 lines
978 B
Lua
37 lines
978 B
Lua
NoiseAnimation = {}
|
|
class('NoiseAnimation').extends(NobleSprite)
|
|
|
|
function NoiseAnimation:init(x, y)
|
|
NoiseAnimation.super.init(self, "assets/sprites/noise", true)
|
|
self.animation:addState("run", 2, 11)
|
|
self.animation:addState("idle", 1, 1)
|
|
self.animation.run.frameDuration = 2.5
|
|
self.animation:setState("idle")
|
|
self:setZIndex(ZIndex.foreground)
|
|
self:setSize(400, 240)
|
|
self:add()
|
|
self:moveTo(x, y)
|
|
|
|
self.state = "idle"
|
|
self.idleFrames = 0
|
|
end
|
|
|
|
function NoiseAnimation:update()
|
|
if self.state == "idle" then
|
|
self.idleFrames -= 1
|
|
if self.idleFrames <= 0 then
|
|
self.state = "run"
|
|
self.animation:setState("run")
|
|
end
|
|
else
|
|
local r = math.random(0)
|
|
if r < 0.01 then
|
|
self.state = "idle"
|
|
self.idleFrames = math.random(30, 100)
|
|
self.animation:setState("idle")
|
|
else
|
|
self.animation:setState("run")
|
|
end
|
|
end
|
|
end
|