Advanced Tiled Loader - No longer maintained

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader

Post by KingRecycle »

So after spending a few hours trying to figure this out I got nowhere. The character will not move tiles and only will change it's looking direction.

Apparently it's not getting passed: if tile == nil then return end

So I believe it thinks the tile is nil and I can't figure out how to fix this.

So if anyone can help me out, thanks.


Update: I figured out the problem with him not moving.

Now I can't figure out how to check if the tile is an obstacle or not when it's a different layer. I tried following the Ground example but to no prevail.
Can someone help me out with code example on how this works.
Attachments
Test2.love
(202.12 KiB) Downloaded 87 times
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

All of the layers are stored in map.tileLayers or map.objectLayers under their layer name. If "ground" is a tile layer you are able to get it by accessing map.tileLayers["ground"].

If you wanted to check all tile layers and see if a certain tile is an obstacle then you could use something like this:

Code: Select all

for name, layer in pairs(map.tileLayers) do
   if layer(x, y) and layer(x, y).properties.obstacle then return "This tile is an obstacle!" end
end
Let me know if you're still confused.
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader

Post by KingRecycle »

Kadoba wrote:All of the layers are stored in map.tileLayers or map.objectLayers under their layer name. If "ground" is a tile layer you are able to get it by accessing map.tileLayers["ground"].

If you wanted to check all tile layers and see if a certain tile is an obstacle then you could use something like this:

Code: Select all

for name, layer in pairs(map.tileLayers) do
   if layer(x, y) and layer(x, y).properties.obstacle then return "This tile is an obstacle!" end
end
Let me know if you're still confused.
I think I figured it out but is there a way to check what layer the tile is from based on it's position?

Like if I wanted to know if the tile at 3, 6 was a Ground Layer or Furniture Layer.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

Well, it's possible to have multiple tiles at the same location if they are on different layers, so you have to check them all. To get a tile at a specific location and layer (for example, layer "ground" and location (3,6) then you can use the expression map.tileLayers["Ground"](3, 6).


Here's a function that will check a tile location on all tile layers for an obstacle. If it finds one then it returns true and the name of the layer it was on.

Code: Select all

function checkObstacle(map, x, y)
    for name, layer in pairs(map.tileLayers) do
        if layer(x, y) and layer(x, y).properties.obstacle then 
            return true, name
        end
    end
    return false
end
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader

Post by KingRecycle »

Been playing with this for awhile and I am probably missing something but I get this error when I run that function.

Image
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

Oops. You want layer.tileData. That's where all of the tiles are stored. My bad.

Code: Select all

function checkObstacle(map, x, y)
    for name, layer in pairs(map.tileLayers) do
        if layer.tileData(x, y) and layer.tileData(x, y).properties.obstacle then
            return true, name
        end
    end
    return false
end
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader

Post by KingRecycle »

Kadoba wrote:Oops. You want layer.tileData. That's where all of the tiles are stored. My bad.

Code: Select all

function checkObstacle(map, x, y)
    for name, layer in pairs(map.tileLayers) do
        if layer.tileData(x, y) and layer.tileData(x, y).properties.obstacle then
            return true, name
        end
    end
    return false
end
Thanks a lot! This has been troubling me for awhile. I'm glad I can come on here and ask such questions and actually get help. I appreciate it.

I have a friend who knows Lua and Love2D better than me and when I ask him he just says, "You are doing it wrong. Good luck."


Can someone explain how objects work and explain the use for them? It seems I can't get it's tilex and tiley position. So i'm not sure how to check if the player is looking at it or not.
Last edited by KingRecycle on Fri May 25, 2012 9:49 pm, edited 1 time in total.
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 objects just hold the data for real game objects. You're just suppose to read data from them and throw them away. A real game object system is very dependent on how you create the infrastructure for your game so it is outside the scope of ATL.
User avatar
KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Re: Advanced Tiled Loader

Post by KingRecycle »

Kadoba wrote:ATL objects just hold the data for real game objects. You're just suppose to read data from them and throw them away. A real game object system is very dependent on how you create the infrastructure for your game so it is outside the scope of ATL.
Ah, I think I get it. Thanks again.


Another question,

I'm trying to check if the tile has the useable property. It works fine if the tile is in the Ground layer but in another layer it's as if it's not there. I changed the checkObstacle function to check for usable property but it doesn't see it. It gives me nil.

Code: Select all

function checkUseable(map, x, y)
    for name, lay in pairs(map.tileLayers) do
	
	if lay.tileData(x, y).properties.useable == nil then
		
	
		return false end
	
        if lay.tileData(x, y).properties.useable then

            return true, name
 
		end
    end

    return false
end
User avatar
SimonLarsen
Party member
Posts: 100
Joined: Thu Mar 31, 2011 4:47 pm
Location: Denmark
Contact:

Re: Advanced Tiled Loader

Post by SimonLarsen »

I'm a bit confused about how Tiles in TileLayers are assigned id's.
I have a 16x16 tile map and I would expect the tile at (x,y) to have id (x + y*16 + 1) but it appears that the id's are assigned as (x + y + 1).

I'll try to illustrate.
Expected id's:
7GHbC.png
7GHbC.png (4.14 KiB) Viewed 468 times
Actual id's:
f8WQl.png
f8WQl.png (4.24 KiB) Viewed 468 times
This is a problem because several tiles will have the same id so there is no way to distinguish them. What am I missing here?
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests