I’m using a tile layer to ‘draw’ some paths for my enemies to follow which I’ll refer to in code, i.e. check properties in the path tiles. I’m using a single opaque tile to do this in a separate tile layer.
The tiles show on my map when the map loads, why doesn’t this hide them?
local enemyPath = map:getTileLayer("Enemypaths")
enemyPath:hide()
Also is this the best approach, i.e. will I still be able to check for the tiles and reference their properties if they are hidden?
Your code does work as long as you create the visual first.
Here it is in action with a loop to show tile id’s for that tile layer (even though they are hidden)
display.setStatusBar( display.HiddenStatusBar )
lime = require("lime")
local map = lime.loadMap("Test.tmx")
visual = lime.createVisual(map)
local enemyPath = map:getTileLayer("Enemypaths")
enemyPath:hide()
-- If layer exists
if(enemyPath) then
-- Get the tiles
local tiles = enemyPath.tiles
-- Ensure tiles is not nil
if(tiles) then
-- Loop through tiles
for i=1, #tiles, 1 do
-- print gid
print("Tile:" .. i .. " id:" .. tiles[i].gid)
end
end
end
Thanks for your help. I’m afraid the following doesn’t work, this is my ‘constructor’ to build a map class:
function new(mapName)
local self = lime.loadMap("levelOneMap.tmx")
local visual = lime.createVisual(self)
local enemyPaths = self:getTileLayer("enemyPaths")
enemyPaths:hide()
print(enemyPaths.name)
return self
end
There are no errors and the print statement prints the layer name but the tiles aren’t hidden in the simulator.