A TileLayer's tileData is a
grid, which is just a 2d array with extra functionality built into it.
If you're making your own maps inside ATL then here are the steps you'll need to take:
- Use Map.newTileSet() to create a TileSet from an image. The tiles are automatically created and inserted into the map.
- Use Map.newTileLayer() to create a new TileLayer.
- Put your tiles from map.tiles into your new TileLayer's tileData
You can use the
ATL wiki for reference.
Here's a quick example:
Code: Select all
-- Load the module
local ATL = require "AdvTiledLoader"
-- Create a new map
local map = ATL.Map:new("My Map", 100, 100, 32, 32, "isometric")
-- Load the TileSet image
local image = love.graphics.newImage("MyTileSet.png")
-- Create a new TileSet. The last parameter is the starting gid
map:newTileSet(image, "My TileSet", 32, 32, image:getWidth(), image:getHeight(), 1)
-- Create an empty TileLayer
local myLayer = map:newTileLayer("My TileLayer")
-- Set tile (1,1) to the first tile cut out of the TileSet
myLayer.tileData:set(1, 1, map.tiles[1])
-- Set all tiles in a rectangle from (1,1) to (5,5) to the second tile cut out from the TileSet
for x, y, tile in myLayer.tileData:rectangle(1,1,4,4) do
myLayer.tileData:set(x, y, map.tiles[2])
end
-- Flip tile (3,3)
myLayer.tileData:flipTileX(3,3)
One thing you need to be aware of is the gid of the tiles. The gid is a number assigned to the tile so you can retreive it with map.tiles[gid]. Whenever you create a TileSet you must also give it a starting gid. When the TileSet cuts out the tiles it will assign gids to each tile.
See this wiki article for more information.
Basically if you have multiple TileSets inside of a map you need to make sure they don't cut out tiles that have clashing gids.The easiest way would probably be to increase the starting gid by a certain amount every time you add a new TileSet. For example, your first TileSet could have a starting gid of 1. Your second TileSet could have a starting gid of 10001. The third could be 20001 and so on.
If you need any more help let me know.