I’ve been struggling with grabbing properties as well, but I don’t think it has to do with moving tile layer 2 to the front. There are still issues with the properties related to this link (which we have discussed earlier):
http://developer.anscamobile.com/forum/2011/08/27/moving-tile-leaves-tile-values-detection-behind
However I’ve figured out some ways of dealing with it.
Using the code from my last post, you can check for a property this way:
--Assuming there is a tile at tile layer 2 with the property "door" and the value "open"
gridPosition = { row = 1, column = 1 }
local tileGrab = tileLayer2:getTileAt( gridPosition )
if tileGrab.door then
print ("Door found")
end
if tileGrab.door == "open" then
print ("Door is open")
end
Note! You might have to pass the true argument if you move your tiles around:
local tileGrab = tileLayer2:getTileAt( gridPosition, true )
Other code snippets that might be useful:
-- Lists the properties and values of all tiles that have got properties
local tiles = tileLayer2.tiles
for i=1, #tiles, 1 do
local tileProperties = tiles[i]:getProperties()
for key, value in pairs(tileProperties) do
local property = tileProperties[key]
print(property:getName(), property:getValue())
-- Here you can store each tile (tiles[i]) in a table if needed!
-- Or you can check for specific properties (if key == "door") before you store them.
end
end
-- Lists the values of all the tiles with property "door"
local tiles = tileLayer2.tiles
for i = 1,#tiles do
if tiles[i]:getProperty("door") then
print (tiles[i]:getPropertyValue("door"))
end
end
-- Lists every grid-position which have a tile with property "door".
local tiles = tileLayer2.tiles
for i = 1,#tiles do
if tiles[i]:getProperty("door") then
print ("There is a door at row:"..tiles[i].row.." column:"..tiles[i].column)
end
end
If you need to remove or set a property you can do it this way:
gridPosition = { row = 1, column = 1 }
local tileGrab = tileLayer2:getTileAt( gridPosition )
--remove a property:
tileGrab.door = nil
--set a property:
tileGrab.door = "closed"
From this you should be able to tweak the code to your need. Just be sure to use the latest Beta.
Hope this might help.
[import]uid: 129287 topic_id: 27205 reply_id: 110775[/import]