feat: use lazy loading with charset

This commit is contained in:
Kazhnuz 2021-03-21 15:56:35 +01:00
parent 16d1f68805
commit 0f08296cf3
2 changed files with 9 additions and 3 deletions

View file

@ -8,7 +8,6 @@ local TweenManager = require "game.modules.tweenmanager"
function Player:new(world, x, y, id)
Player.super.new(self, world, "player", x, y, 16, 16, true)
self.charset:addTexture("perso")
self.active = game.characters:getActiveCharacterData()
self.emblems = {}

View file

@ -41,6 +41,13 @@ function Charset:addChar(ii, jj)
return char
end
function Charset:getTexture(charsetName)
if (self.list[charsetName] == nil) then
self:addTexture(charsetName)
end
return self.list[charsetName]
end
function Charset:addTexture(charsetName)
self.list[charsetName] = love.graphics.newImage(folder .. charsetName .. ".png")
end
@ -60,13 +67,13 @@ function Charset:getStandingFrame(charID, direction)
end
function Charset:draw(charsetName, charID, direction, x, y)
local drawable = self.list[charsetName]
local drawable = self:getTexture(charsetName)
local quad = self:getRunningFrame(charID, direction)
love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 11, 32)
end
function Charset:drawStanding(charsetName, charID, direction, x, y)
local drawable = self.list[charsetName]
local drawable = self:getTexture(charsetName)
local quad = self:getStandingFrame(charID, direction)
love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 11, 32)
end