improvement: lazyload sti objects

This commit is contained in:
Kazhnuz 2021-03-23 18:26:05 +01:00
parent fe467119d2
commit 4e4afd2baf
2 changed files with 12 additions and 1 deletions

View file

@ -25,7 +25,7 @@ function TiledMap:getDimensions()
end end
function TiledMap:loadObjects() function TiledMap:loadObjects()
self.wrapper:loadObjects() --self.wrapper:loadObjects()
end end
-- TILE FUNCTIONS -- TILE FUNCTIONS

View file

@ -8,6 +8,7 @@ function StiWrapper:new(owner, mapfile, x, y)
self.y = y or 0 self.y = y or 0
self.objectlayer = 0 self.objectlayer = 0
self.isLoaded = false
end end
function StiWrapper:getDimensions() function StiWrapper:getDimensions()
@ -22,12 +23,20 @@ function StiWrapper:resize(w, h)
end end
function StiWrapper:update(dt) function StiWrapper:update(dt)
self:lazyLoad()
self.sti:update(dt) self.sti:update(dt)
end end
-- OBJECT FUNCTIONS -- OBJECT FUNCTIONS
-- Handle objets -- Handle objets
function StiWrapper:lazyLoad()
if (not self.isLoaded) then
self:loadObjects()
self.isLoaded = true
end
end
function StiWrapper:loadObjects() function StiWrapper:loadObjects()
self:loadCollisions() self:loadCollisions()
self:loadPlayers() self:loadPlayers()
@ -179,6 +188,7 @@ end
-- Draw the map -- Draw the map
function StiWrapper:drawUpperLayers() function StiWrapper:drawUpperLayers()
self:lazyLoad()
if (self.objectlayer > 0) then if (self.objectlayer > 0) then
for i = self.objectlayer, self.nbrLayer, 1 do for i = self.objectlayer, self.nbrLayer, 1 do
self:drawLayer(i) self:drawLayer(i)
@ -187,6 +197,7 @@ function StiWrapper:drawUpperLayers()
end end
function StiWrapper:drawLowerLayers() function StiWrapper:drawLowerLayers()
self:lazyLoad()
for i = 1, self.objectlayer, 1 do for i = 1, self.objectlayer, 1 do
self:drawLayer(i) self:drawLayer(i)
end end