31 lines
745 B
Lua
31 lines
745 B
Lua
local Entity = require "scenes.levels.entities.parent"
|
|
local Animator = require "core.modules.assets.animator"
|
|
|
|
local GFX = Entity:extend()
|
|
|
|
function GFX:new(level, x, y, spritename, animID)
|
|
local width, height
|
|
self.name = spritename
|
|
self.animID = animID
|
|
width = 16
|
|
height = 16
|
|
GFX.super.new(self, level, "gfx", x - (width/2), y - (height/2), width, height)
|
|
self.animation = self.scene.assets.sprites[spritename]:clone()
|
|
self.duration = self.animation:getAnimationDuration()
|
|
self.timer = 0
|
|
end
|
|
|
|
function GFX:update(dt)
|
|
self.timer = self.timer + dt
|
|
self.animation:update(dt)
|
|
if (self.timer >= self.duration) then
|
|
self:destroy()
|
|
end
|
|
end
|
|
|
|
function GFX:draw(dt)
|
|
self.animation:draw(self.x, self.y)
|
|
end
|
|
|
|
return GFX
|