Advanced Tiled Loader - No longer maintained

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

KingRecycle wrote:One last question, How would I go about changing the tile within the code?
You need to replace the tile inside a layer's tiledata with another tile. All tile types in a map can be found in map.tiles indexed by their gid.

Let's say you wanted to replace all tiles with the name property set to "rock" with another tile named "rock2"

Code: Select all

-- Find the rock2 tile
local rock2
for _,tile in pairs(map.tiles) do
   if tile.properties.name == "rock" then rock = tile end
end

-- Iterate through all tiles and replace rock with rock2
local layer = map.tileLayers["ground"]
for x, y, tile in layer.tileData:iterate() do
   if tile.properties.name == "rock" then
      layer.tileData:set(x, y, rock2)
   end
end
gregkwaste wrote:i've made a post in my topic, but i think the question suits more here.

Is there anything like tiledata structure in objectlayers?
Sort of. ObjectLayer.objects contains all of the objects in the layer but it's not a special structure like tileData. It's just a simple table.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

ATL has been updated to version 0.11.0. There's been a couple of substantial changes. They unfortunately will break current code.

FIrst off, map.tileLayers and map.objectLayers are now combined into one table called map.layers. This is simpler and it's a preliminary move to get ready for the new image layers coming in Tiled 0.9.0. I didn't think 3 different tables for looking up layers was a very good idea so they got combined.

To tell them apart they now remember their class name. So to iterate over all TileLayers in a map you now do this:

Code: Select all

for name, layer in pairs(map.layers) do
   if layer.class == "TileLayer" then
      -- do something
   end
end
The second major change is that the functionality of tileData is now built into TileLayers themselves. Basically any operation you did on tileData is now just done on the TileLayer (so tileLayer.tileData:iterate() is now just tileLayer:iterate(). The most common operations in ATL is done on tiles so this change saves a step and makes it look nicer.

Another change is that there is a new map.__call() function that will return the layer by name. So map("ground") is the same as map.layers["ground"].

All of these changes together simplifies the operation on tiles.

Code: Select all

-- Old way of iterating over tiles
for x, y, tile in map.tileLayers["ground"].tileData:iterate() do
end

-- New way of iterating over tiles
for x, y, tile in map("ground"):iterate() do
end
The last substantial change is the introduction of custom layers. Custom layers are layers that the user defines and is inserted into the map. The name is entirely an abstraction. Any table can be used as a custom layer and, in fact, custom layers were used before this version. To use them before you only had to have a table with a draw() function and insert it into the map's drawList (Now renamed layerList). Even though this was practically necessary to make a game with ATL it wasn't obvious at all. Now there is an interface for doing it.

Along with this, map.callback() has been created. This function will forward callbacks to all layers if the functions exist. This is intended to forward love callbacks to custom layers but you can trigger your own callbacks as well.

Code: Select all

-- Create a new custom layer
local layer = map.newCustomLayer("LayerName")
layer.time = 0

-- Update the layer
function layer:update(dt) 
   self.time = self.time + dt 
end

-- Draw the layer
function layer:draw() 
   love.graphics.print("It has been " .. self.time, 0, 0) 
end

-- Forward the update callback to the map
function love.update(dt) 
   map:callback("update", dt)
end

-- Draw the map
function love.draw()
   -- map:draw is  now a shortcut for map:callback("draw").
  map:draw() 
end
Here is a list of changes. Let me know if you have any questions.

CHANGES:

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.newCustomLayer() 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.
gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by gregkwaste »

I had pesronally had a hard time keeping up with the old method and that is what i understand for now, i think i'll keep up with the old one in order to get a bit more comfortable with at the moment :P

Now something i think i figured out about objects.

i had a very stupid problem trying to move some objects in an object layer , i just now i concluded that it was not due to faulty code. The way that the code iterates in the object tables follows the exact same way that the user enters the tiles in tiled. That is very annoying because it forces you to replace all the objects from the beginning if you want to move them with a specific order (just as i do...). It would be a lot nicer if the loader loaded somehow sorted the objects by their map position.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by Karai17 »

Hey, mate! Awesome update, I've updated my code and it all works great!

I am having an issue, though, and I don't think it is due to the update. When I enable autoDrawRange(), my sprites seem to disappear after a step outside of small area. Think you could take a gander and point me in the right direction?

https://dl.dropbox.com/u/12958391/KLD-borked.zip.love
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by KingRecycle »

Karai17 wrote:Hey, mate! Awesome update, I've updated my code and it all works great!

I am having an issue, though, and I don't think it is due to the update. When I enable autoDrawRange(), my sprites seem to disappear after a step outside of small area. Think you could take a gander and point me in the right direction?

https://dl.dropbox.com/u/12958391/KLD-borked.zip.love

You are leaving the draw range so your player is not drawn.

You probably want it to be around the player.

map:autoDrawRange(player.x, player.y, scale, 32)


So how would you do tileData(x,y) now?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by Karai17 »

KingRecycle wrote:
Karai17 wrote:Hey, mate! Awesome update, I've updated my code and it all works great!

I am having an issue, though, and I don't think it is due to the update. When I enable autoDrawRange(), my sprites seem to disappear after a step outside of small area. Think you could take a gander and point me in the right direction?

https://dl.dropbox.com/u/12958391/KLD-borked.zip.love

You are leaving the draw range so your player is not drawn.

You probably want it to be around the player.

map:autoDrawRange(player.x, player.y, scale, 32)
Thanks for the reply! Both tx and ty incorporate player.x and player.y to calculate where the camera should be sitting. When I change autpDrawRange() to player.x and player.y, the map no longer updates and it gets cut off.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by KingRecycle »

Well, mine seems to work. So I don't think it's tileloader. I tried putting a rectangle to show where it is but it doesn't like scale I think.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by Karai17 »

Why wouldn't it like scale? Scale is supposed to be there, no?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by KingRecycle »

Karai17 wrote:Why wouldn't it like scale? Scale is supposed to be there, no?
Yeah it's not scale. I tried a few things and it either broke it more or didn't do anything.

If you do figure out please update me as I'm really curious on what the problem is.

==================

So I'm trying to get mouse position within the map but mouse position gets it's screen position.

Anyone know how to get it's map position?
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader - Updated to 0.11.0!

Post by Kadoba »

gregkwaste wrote:i had a very stupid problem trying to move some objects in an object layer , i just now i concluded that it was not due to faulty code. The way that the code iterates in the object tables follows the exact same way that the user enters the tiles in tiled. That is very annoying because it forces you to replace all the objects from the beginning if you want to move them with a specific order (just as i do...). It would be a lot nicer if the loader loaded somehow sorted the objects by their map position.
That problem seems very specific. You can always just sort the objects yourself after you load the map.

Code: Select all

function sortByPosition(a, b)
    if a.y == b.y then return a.x < b.x end
    return a.y < b.y
end

for name, layer in pairs(map.layers) do
   if layer.class == "ObjectLayer" then
      table.sort(layer.objects, sortByPosition)
   end
end
Karai17 wrote:Hey, mate! Awesome update, I've updated my code and it all works great!

I am having an issue, though, and I don't think it is due to the update. When I enable autoDrawRange(), my sprites seem to disappear after a step outside of small area. Think you could take a gander and point me in the right direction?

https://dl.dropbox.com/u/12958391/KLD-borked.zip.love
I'm pretty sure this is because Object:updateDrawInfo() isn't being called. Objects keep an internal table that holds their drawing information. Anytime you resize or move the object you should call that function. Having said that, I recommend you don't use ATL objects at all as real objects. They're called "objects" because that's what Tiled calls them, but they're really just placeholder data for your own objects. The correct usage is to read data from them and replace ObjectLayers with your own custom layers. I know this isn't obvious and I've been trying to take steps to make new users more aware of it.

KingRecycle wrote:Anyone know how to get it's map position?
I believe the mouse position will always be the position on the screen. But you can easily get the map position by adding or subtracting the translation (I forget which).
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests