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
function TiledMap:loadObjects()
self.wrapper:loadObjects()
--self.wrapper:loadObjects()
end
-- TILE FUNCTIONS

View file

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