Uhfgood
Prole
Posts: 35
Joined: Sat Jul 28, 2012 10:04 pm
Location: Oregon, US
Contact:

Thanks, I just put that code in and it works fine, so thanks again.
xenodora
Prole
Posts: 1
Joined: Sat Jan 26, 2013 5:02 pm

This is some code I wrote to convert all the rectangles, polygons, polylines and ellipses in an object layer into static shapes and import them into a love.physics world.

Code: Select all

function importObjectLayer(world, layer)
for i = 1, #layer.objects do
local obj = layer.objects[i]
local shp = nil
if obj.polyline then
shp = love.physics.newChainShape(false, unpack(obj.polyline))
elseif obj.polygon then
shp = love.physics.newChainShape(true, unpack(obj.polygon))
elseif obj.gid then
--object is a tile, skip
--todo: Consider reading the tile properties to determine if a special shape should be added.
elseif obj.ellipse then
if obj.width == obj.height then
--proper circle
local r = obj.width / 2
shp = love.physics.newCircleShape(r, r, r)
else
--an ellipse
local points = {}
local xr = obj.width / 2
local yr = obj.height / 2
for i=1, 8 do
local ang = math.pi * 2 * i / 8
points[#points + 1] = xr * (1 + math.cos(ang))
points[#points + 1] = yr * (1 + math.sin(ang))
end
shp = love.physics.newChainShape(true, unpack(points))
end
else
--rectangles
--Don't use love.physics.newRectangleShape(), as it will create a rectangle centered around 0, 0.
shp = love.physics.newPolygonShape(0, 0,  obj.width, 0,  obj.width, obj.height,  0, obj.height)
end
if shp ~= nil then
local bdy = love.physics.newBody(world, obj.x, obj.y, "static")
local fxt = love.physics.newFixture(bdy, shp)
end
end
end

The function can be called like this:

Code: Select all

love.physics.setMeter(32)
world = love.physics.newWorld(0, 0, true)
importObjectLayer(world, map("Obstructions"))
Love's physic engine can then be used to handle collision detection with the terrain or whatever else you decide to mark out.
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Tiled 0.9.0 was released yesterday so between getting support for that and refactoring the loading and rendering code I'm going to be busy. I just wanted to let everyone know I'm hard at work on the next version.

Also thanks for the code xenodora. I'm still reviewing your commit on github.
Uhfgood
Prole
Posts: 35
Joined: Sat Jul 28, 2012 10:04 pm
Location: Oregon, US
Contact:

Thanks for all the hard work Kadoba!
Uhfgood
Prole
Posts: 35
Joined: Sat Jul 28, 2012 10:04 pm
Location: Oregon, US
Contact:

How does one currently access an object in an object layer?
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Code: Select all

map("ObjectLayer").objects[number]
I believe the number is the order of placement inside Tiled.
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Just a status update.

I've been working on the next version of ATL for a while now and I've decided to take it in a new direction. I want to put more of an emphasis as ATL as a loader and less on rendering. I've realized that ATL just tries to do too many things outside of its design scope and it really affects the complexity and maintainability of the library. That means I'm going to cut out a lot of fat. In some cases this will mean more work for the user. However I'm convinced that by narrowing the focus this will ultimately make ATL easier to understand, more flexible, and a better library overall.

The new loading system will make it possible to convert formats between tmx files, lua files, simple tables, and ATL maps. This means you can do things like turn exported lua map files back into the native tmx format or use ATL just for loading/saving map data and come up with your own rendering scheme.

Additionally, I am seriously considering dropping rendering support for isometric maps. From what I have experienced it is a rarely used feature and it has a high cost in terms of maintainability and code complexity. It will be possible to load/save between isometric files and simple tables, you just wont be able to turn them into renderable ATL maps.

It will likely be late next week before I finish the new version. Here's what the current patch notes for 0.13.0 looks like:
• Removed rendering support for isometric maps
• Added Convert.lua to handle conversions between tmx, lua, tables, and ATL maps.
• Added support for Tiled 0.9.0 features
• Revamped rendering algorithm. Improved speeds significantly under certain conditions.
• Maps no longer keep track of the draw range. The values for it must be passed manually when calling draw functions.
• Improved interface for flipped and rotated tiles.
Katherine1
Prole
Posts: 2
Joined: Fri Mar 22, 2013 5:24 am

I've been trying to learn to use ATL recently, and I have a situation where I need to know the first GID of one of the two tilesets attached to the map I'm loading. This seemed like it would be fairly straight forward. The map documentation says that tileset information is held in map.tilesets. When I try to access it, though, I get "Error: main.lua:26: attempt to call field 'tilesets' (a table value)"

I couldn't find anything in the documentation that would tell me how to get that information other that this, so anyone know how to actually do it?
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

It sounds like you're trying to call the tilesets table like a function.

Code: Select all

-- you might be doing this:
map.tilesets("tilesetname").firstgid

-- when you need to be doing this:
map.tilesets["tilesetname"].firstgid
Katherine1
Prole
Posts: 2
Joined: Fri Mar 22, 2013 5:24 am