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.
Advanced Tiled Loader - No longer maintained
- KingRecycle
- Prole
- Posts: 44
- Joined: Thu May 24, 2012 1:01 am
Re: Advanced Tiled Loader
- Attachments
-
- Test2.love
- (202.12 KiB) Downloaded 94 times
Re: Advanced Tiled Loader
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:
Let me know if you're still confused.
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
- KingRecycle
- Prole
- Posts: 44
- Joined: Thu May 24, 2012 1:01 am
Re: Advanced Tiled Loader
I think I figured it out but is there a way to check what layer the tile is from based on it's position?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:Let me know if you're still confused.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
Like if I wanted to know if the tile at 3, 6 was a Ground Layer or Furniture Layer.
Re: Advanced Tiled Loader
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.
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
- KingRecycle
- Prole
- Posts: 44
- Joined: Thu May 24, 2012 1:01 am
Re: Advanced Tiled Loader
Been playing with this for awhile and I am probably missing something but I get this error when I run that function.
Re: Advanced Tiled Loader
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
- KingRecycle
- Prole
- Posts: 44
- Joined: Thu May 24, 2012 1:01 am
Re: Advanced Tiled Loader
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.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
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.
Re: Advanced Tiled Loader
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.
- KingRecycle
- Prole
- Posts: 44
- Joined: Thu May 24, 2012 1:01 am
Re: Advanced Tiled Loader
Ah, I think I get it. Thanks again.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.
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
- SimonLarsen
- Party member
- Posts: 100
- Joined: Thu Mar 31, 2011 4:47 pm
- Location: Denmark
- Contact:
Re: Advanced Tiled Loader
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: Actual id's: 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?
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: Actual id's: 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?
Who is online
Users browsing this forum: No registered users and 2 guests