------------------------------------------------------------------------I feel like I should address this myself. I probably won't be updating ATL in it's current state. ATL was my first major coding project and even though I dedicated many, many hours to it and learned a lot it I've never been happy with the results. Basically the scope is just way too large and I am way too inexperienced of a programmer. Instead of focusing just on the loading aspect of the library I tried to create an all-in-one solution that includes the rendering, saving, and real-time modification of maps and ended up with a huge inflexible mess. If I do come back to ATL I will likely salvage it into a different project with a much more focused goal.
I also apologize to anyone who feels like they wasted their time with ATL and it did not meet their expectations, or to anyone who genuinely finds it useful and is now finding out I don't plan to maintain it any longer. I honestly gave it my best shot but I've come to realize that is was really never a good library in the first place, which is a pretty hard pill to swallow.
Of course if someone does wish to maintain the library it is on github for anyone to extend, but in its present form I would personally discourage its use as it is now fairly out of date along with all of its previous limitations.
Advanced Tiled Loader (ATL) loads and renders Tiled maps inside of the Löve game framework.
Supported features include:
- Multiple Layers
- All object types (regular, polygon, and tile)
- Properties
- Transparent colors
- Margins and spacing
- External tilesets
- zlib/gzip decompression
- Isometric maps
- Flipped and rotated tiles
Code: Select all
-- Gets the loader
loader = require("AdvTiledLoader/loader.lua")
-- Path to the tmx files. The file structure must be similar to how they are saved in Tiled
loader.path = "maps/"
-- Loads the map file and returns it
map = loader.load("desert.tmx")
-- Draws the map
map:draw()
-- Limits the drawing range of the map. Important for performance
map:setDrawRange(0,0,love.graphics.getWidth(), love.graphics.getHeight())
-- Automatically sets the drawing range to the size of the screen.
map:autoDrawRange(tx, ty, scale, padding)
-- Accessing individual layers
map.layers["layer name"]
-- A shortcut for accessing specific layers
map("layer name")
-- Finding a specific tile
map.layers["layer name"]:get(5,5)
-- A shortcut for finding a specific tile
map("layer name")(5,5)
-- Iterating over all tiles in a layer
for x, y, tile in map("layer name"):iterate() do
print( string.format("Tile at (%d,%d) has an id of %d", x, y, tile.id) )
end
-- Iterating over all objects in a layer
for i, obj in pairs( map("object layer").objects ) do
print( "Hi, my name is " .. obj.name )
end
-- Find all objects of a specific type in all layers
for _, layer in pairs(map.layers) do
if layer.class == "ObjectLayer" then
for _, obj in pairs(player.objects) do
if obj.type == "enemy" then print(obj.name) end
end
end
end
-- draw the tile with the id 4 at (100,100)
map.tiles[4]:draw(100,100)
-- Access the tile's properties set by Tiled
map.tiles[4].properties
-- Turns off drawing of non-tiled objects.
map.drawObjects = false
Please post if you have any questions or feedback.
Code: Select all
CHANGES:
0.12.1 (10/31/12)
- TileLayer:drawAfterTile() has been reworked into TileLayer:newAfterTileFunction()
- Arguments for the Map functions that create and add map components directly to the
map have changed. (Map:newTileLayer(), Map:newObjectLayer(), etc)
0.12.0 (10/17/12)
- Maps can now be saved with Loader.save()
- Introduced ATL properties
0.11.0 (09/04/12)
- Renamed Map.drawList to Map.layerOrder.
- Renamed Map.drawPosition to Map.layerPosition.
- Combined Map.tileLayers and Map.objectLayers into one table - Map.layers.
- The functionality of tileData is now combined with TileLayer.
- Changed Map.__call to return layers by their name.
- Created Map.callback() to forward love callbacks to layers.
- Created Map.swapLayers()
- Created Map.newCustomLayers() which is a new interface for creating custom layers.
- Classes now remember their class name.
- Removed object movement functions to deter the use of objects other than reading data from.
- Removed the fixPO2 option for the loader.
- Generally cleaned up the code and made it easier to read.
- Properties are now automatically converted into proper types (numbers, boolean, string) when loaded.
- Readme file changed. There is now a new VERSION.txt file for version information.
0.10.2 (04/26/12)
- Relative paths now fully work. Before, ATL did not like to travel backwards in
a directory from a map file to reach a tileset.
0.10.1 (04/20/12)
- Added quit compatibility for love 0.8.0 in the example files
- AdvTiledLoader can now be correctly required from any subfolder
- Fixed a bug with map.drawObjects not working
- Undefined object colors will now appear grey instead of black
- Added Loader.drawObjects and Loader.useSpriteBatch values. These values will be
applied to any new map that is loaded.
- Fixed a bug where the map would be drawn incorrectly if the map's width and height
were different
0.10.0 (04/11/12)
- 2d arrays are replaced with a much easier to use grid class.
- Tiles are now directly inserted into TileLayer.tileData. You no longer have to
look them up via their ID in Map.tiles.
- Tile indexes are now the same as their coordinants as shown inside the Tiled.
- Added support for Tiled version 0.8.0. This includes tile rotation, polygon
objects, polyline objects, tilemap offset, and tilemap propterties.
- Moved the object drawing code from object layers to the objects themselves.
- Added functions tileCopy(), tilePaste(), tileRotate(), tileFlipX(), tileFlipY()
to TileLayers.
0.9.0 (8/22/11)
- Advanced Tile Loader now has a wiki page and a github repository!
- Cleaned up the code quite a bit.
- Classes are now broken up into individual files rather than grouping similar
ones into one file.
- Many identifiers have been changed to be less confusing and more consistent. Now
camelCase is used to separate words instead of underscores. Internal
functions and data are now prefixed with an underscore.
- Sprite batch mode can now be set through the map or through individual tile
layers. Tile layer settings take precedence.
- A bug with layer transparency has been fixed.
- Tile:draw() now accepts parameters for scaling, rotation, and offset.
- TileLayer:drawAfterTile() now works with multiple functions
- Forcing a redraw is now automatic when you switch sprite batch modes.
- Added support for flipped tiles that were introduced in Tiled version 0.7.1
0.8.2 (5/9/11):
- Tileset images are now cached between maps.
- Added an option to automatically pad images for PO2. To do this set
Loader.fix_po2 to true.
- Changed Map.tl and Map.ol back to their old names. Map.tl and Map.ol remain as
aliases.
- Tile layers can now render using sprite batches by setting TileLayer.use_batch
to true.
- Added an init.lua file.
- Removed hardcoded require() paths. Added in global TILED_LOADER_PATH to point
to the library path.
- Renamed the TileSet functions getWidth() and getHeight() to tilesWide() and
tilesHigh().
0.8.1 (3/10/11):
- Renamed Map.tilelayers and Map.objectlayers to Map.tl and Map.ol respectively.
- Added function Tile.drawAfterTile()
- You may now define a draw() function for objects which overrides the default
drawing routine
0.8.0 (2/28/11):
- Initial release