local anim8 = require "lib.utils.anim8" --- Скорость между кадрами в анимации local ANIMATION_SPEED = 0.1 LEFT = -1 RIGHT = 1 --- @class Animation --- @field animationTable table --- @field animationGrid table --- @field state "idle"|"run"|"hurt"|"attack" --- @field side 1|-1 local animation = {} animation.__index = animation local function new(spriteDir) local anim = { animationTable = {}, animationGrid = {} } -- n: name; i: image for n, i in pairs(spriteDir) do local aGrid = anim8.newGrid(96, 64, i:getWidth(), i:getHeight()) local tiles = '1-' .. math.ceil(i:getWidth() / 96) anim.animationGrid[n] = aGrid(tiles, 1) end anim.state = "idle" anim.side = RIGHT return setmetatable(anim, animation) end function animation:getState() return self.state end --- @param state CharacterState function animation:setState(state, onLoop) self.animationTable[state] = anim8.newAnimation(self.animationGrid[state], ANIMATION_SPEED, onLoop) self.state = state end return { new = new }