I am trying to swap two tiles on one tile layer.
Expected result is - I do an operation on two map positions, and have them swapped - literally - they both exchange their sprites and properties.
I have tried the usual LUA way:
function TileLayer:swapTiles(pos1, pos2)
if (self.tileGrid) then
self.tileGrid[pos1.column][pos1.row], self.tileGrid[pos2.column][pos2.row] = self.tileGrid[pos2.column][pos2.row], self.tileGrid[pos1.column][pos1.row];
end
end
and then the way “of the fist”
[code]function TileLayer:swapTiles(pos1, pos2)
if (self.tileGrid) then
tempTile1 = self.tileGrid[pos1.column][pos1.row];
tempTile2 = self.tileGrid[pos2.column][pos2.row];
self.tileGrid[pos1.column][pos1.row] = tempTile2;
self.tileGrid[pos2.column][pos2.row] = tempTile1;
end
end[/code]
Both ways failed ;(
Then I have thought of using the fresh and cool functions setTileAt and getTileAt… but it makes me to remember the internal GID of a tile in a tileset (or there is a fast and easy way, to get a GID of a tile?).
Graham - sorry I am fiddling with library interface, and place methods in lime-tileLayer.lua, but that was the fastest way to get to the internals (tileGrid) to “check, how I can get this done” [import]uid: 10881 topic_id: 6483 reply_id: 306483[/import]