I just noticed, that if I make large object in Tiled, the enemy is being built when map is loaded, not when it should be built using object culling. I noticed that it will print things from enemy.lua to console when it shouldnt.
This is the code that you gave me to use object culling.
[lua]
local function addObjectType(params)
params.objects = params.objects or {}
local function buildObject(event)
local obj = params.build(event)
if obj then
event.object.builtObject = obj
obj.mapObject = event.object
params.objects[obj] = obj
end
end
for layer in map.objectLayers() do
layer.addObjectListener(“type”, params.objectType, “drawn”, buildObject)
layer.addObjectListener(“type”, params.objectType, “erased”, function(event)
if (event.object.builtObject) then
params.objects[event.object.builtObject] = nil
params.remove(event.object.builtObject)
end
end)
end
end[/lua]
So all in all, my enemy is built when it should be culled