Karai17 wrote:The one I am specifically talking about is a pathfinding library, located here:
viewtopic.php?f=5&t=9322&p=67103#p67103
As you can see in this image, my collision map is offset by 1 on both the x and y axes. So to properly detect collisions for my path finding, I need to add 1 to x/y of my player and the x/y of my monster(s) to match up with my collision map. After the path is generated, I need to then remove 1 form the x/y of those same entities to actually move along the path on the actual map. A bit of a headache and I still don't have it working
In contrast, if ATL were to follow lua convention and index from 1, There is only a single point of reference which needs to be offset, much like traversing an array in nearly any other language that uses index offsets (start from 0).
The only time I can think of where not starting from 1 in lua would be a problem would be when you're using simple arrays as lists. That's because Lua table functions, the # operator, and ipairs will not work properly if you have indexes outside of [1, n+1]. Spacial data structures do not need those so I'm having difficulty understanding where starting from 0 would be a problem.
Actually, taking a look through the Jumper library it seems like the maps have to be fixed dimensions starting from (1,1). It could probably gain a lot from being boundless but that's not my call.
Like I said, ATL use to start tile indexes at (1,1) and that was very confusing since it did not line-up with Tiled. It was frustrating for the exact reasons you are mentioning. You had to take 1 off every time you needed to access a tile.
A possible work-around for you would be to move every tile by +1 x and +1 y once the map is loaded. Or you could just start building your map from (1,1) inside Tiled itself.
Code: Select all
-- Untested code
local ATL = require("AdvTiledLoader")
map = Loader.load("mymap.tmx")
map.width = map.width+1
map.height = map.height+1
for k,layer in pairs(map.layers) do
if layer.className == "ObjectLayer" then
for k, obj in pairs(layer.objects) do
obj.x = obj.x + map.tileWidth
obj.y = obj.y + map.tileHeight
end
elseif layer.className == "TileLayer" then
local cells = {}
for x,y,tile in layer:iterate() do
if not cells[x+1] then cells[x+1] = {}
cells[x+1][y+1] = tile
end
layer.cells = cells
end
end