1.Please just check it over if this is ok and notify if you see any possible problem( I use hump's gamestate (https://github.com/vrld/hump/blob/master/gamestate.lua)so do I need to do anything specialwith that)
2.Is there anyway to check whether an object is still referenced and where?.
Here's the destroy function( I destroy objects so space will be freed in the object pool for that object):
Code: Select all
--GS = hump.gamestate btw
function Map:destroy(destroyPeer)
self.isOld = true
--destroying entities to free up space in
--object pools
local ents = lume.copy(self.entities)
for x, i in pairs(ents) do
if i ~= game.player then
i:destroy()
end
end
local bulls = lume.copy(self.bullets)
for x, i in pairs(bulls) do
i:destroy()
end
self.entites = {}
self.bullets = {}
--destroying tiles
self.allTiles = {}
self.tiles = {}
self.grid = {}
GS.stacks = {}--??
game.map = nil
game.currentMap = nil
self.active = false
self:unpause()
self.player.map = nil
game.player = nil
self.player = {}
lume.clear(self)
end