From 0f08296cf39ac6cc21204fe14f4e5f358302dbd7 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 21 Mar 2021 15:56:35 +0100 Subject: [PATCH] feat: use lazy loading with charset --- .../scenes/overworld/actors/player.lua | 1 - .../scenes/overworld/charsetmanager.lua | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua index 51535ce..27a4e7d 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -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 = {} diff --git a/sonic-radiance.love/scenes/overworld/charsetmanager.lua b/sonic-radiance.love/scenes/overworld/charsetmanager.lua index 2fa72ef..d963dde 100644 --- a/sonic-radiance.love/scenes/overworld/charsetmanager.lua +++ b/sonic-radiance.love/scenes/overworld/charsetmanager.lua @@ -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