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) function Player:new(world, x, y, id)
Player.super.new(self, world, "player", x, y, 16, 16, true) Player.super.new(self, world, "player", x, y, 16, 16, true)
self.charset:addTexture("perso")
self.active = game.characters:getActiveCharacterData() self.active = game.characters:getActiveCharacterData()
self.emblems = {} self.emblems = {}

View file

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