I'm having trouble connecting tile maps and collisions and pretty much everything about them.
I have the tile map set up in Tiled and imported it using AdvTiledLoader so i can "walk" round the map, but i'm not sure how to make solid blocks that my character can't walk through.
I don't mind if i have to draw maps in lua, i just want collisions.
Tilemaps and Collisions`
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Tilemaps and Collisions`
I found Tiled and its library very confusing and ended working on Kikito's tutorial: https://github.com/kikito/love-tile-tutorial/wiki
I recommend a lot to read that tutorial. It's great. Even if you don't feel like using it, it's good to understand how tiles are coded.
And if you want to use it... You can take a look at my little modification of this tutorial (to add collision) decompressing my game ( http://love2d.org/forums/viewtopic.php?f=5&t=3940 ) and look at the "tile.lua" file. This code is not easy to understand so you should take a look at Kikito's tutorial first. Feel free to use whatever code you like if you want
I recommend a lot to read that tutorial. It's great. Even if you don't feel like using it, it's good to understand how tiles are coded.
And if you want to use it... You can take a look at my little modification of this tutorial (to add collision) decompressing my game ( http://love2d.org/forums/viewtopic.php?f=5&t=3940 ) and look at the "tile.lua" file. This code is not easy to understand so you should take a look at Kikito's tutorial first. Feel free to use whatever code you like if you want
Re: Tilemaps and Collisions`
Thanks for the help! I'm probably going to try a bit more on Tiled then if not i'll do it that method. Because i like tiled too much
Anyway, if anyone can help here's my .love: http://api.cld.me/1s1T1K011R170I3K1t19/ ... chris.love
Anyway, if anyone can help here's my .love: http://api.cld.me/1s1T1K011R170I3K1t19/ ... chris.love
Re: Tilemaps and Collisions`
Advanced Tiled Loader only loads Tiled maps and renders them. That's all it's meant to do. I feel like a lot of people get confused into thinking it's some sort of framework to build a real game off of but really the user is meant to pick out the data to put into their own systems. In this case a collision system. Even the examples that come along with the ATL library are sort of stapled together. You could never build a real game from it that way. Objects especially are only meant to read the data from, never to be used as actual game objects. There's just not enough functionality built into them.
For collision detection, basically what you want to do is cycle through all of the tiles when you first load the map and check and see if they are solid, which would be some property you set yourself inside Tiled. If the tile is a solid then create a square the size of the tile inside the collision system you are using.
Here's what that might look like:
If you don't understand something specific about ATL then let me know and I'll try and help you out.
For collision detection, basically what you want to do is cycle through all of the tiles when you first load the map and check and see if they are solid, which would be some property you set yourself inside Tiled. If the tile is a solid then create a square the size of the tile inside the collision system you are using.
Here's what that might look like:
Code: Select all
-- load the map
map = loader.load("MyMap.tmx")
-- For each row
for y, row in pairs(map.tilelayers)
-- For each tile
for x, tilenumber in pairs(row) do
-- Use the tilenumber to get the tile properties from the map. Check and see if that type of tile is solid
if map.tiles[tilenumber].properties.isSolid then
-- If the tile is solid then make a rectangle object in your collision system representing the tile.
collisionSystem:newRectangle(x* map.tilewidth, y * map.tileheight, map.tilewidth, map.tileheight)
end
end
Re: Tilemaps and Collisions`
Kikito's tutorial helped me understand how the tiled map is loaded, albeit its different in the advanced tile loader.
I think that I will use the HardonCollider library http://vrld.github.com/HardonCollider/ for collisions; as I am currently using a modified version of Kikito's tutorial I *should* in theory be able to insert the collision objects into the function that draws the map as I understand it.
Its worth considering anyway.
-Kazagha
I think that I will use the HardonCollider library http://vrld.github.com/HardonCollider/ for collisions; as I am currently using a modified version of Kikito's tutorial I *should* in theory be able to insert the collision objects into the function that draws the map as I understand it.
Its worth considering anyway.
-Kazagha
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Tilemaps and Collisions`
Hi there!
Tile collision is an interesting subject but I just didn't have time to include it on my tutorial. I vastly underestimated the amount of effort it takes to write one!
In any case, there's at least one good tutorial that can help you, at least with the basic concepts - it's "Tilebased games in flash 5". Yes, it's flash, not Lua, so the syntax is different. But the concepts are very similar.
On part 2 they deal with collisions with the map.
I hope this helps. Regards!
Tile collision is an interesting subject but I just didn't have time to include it on my tutorial. I vastly underestimated the amount of effort it takes to write one!
In any case, there's at least one good tutorial that can help you, at least with the basic concepts - it's "Tilebased games in flash 5". Yes, it's flash, not Lua, so the syntax is different. But the concepts are very similar.
On part 2 they deal with collisions with the map.
I hope this helps. Regards!
When I write def I mean function.
Re: Tilemaps and Collisions`
Sorry, I haven't replied to anything. I've started work recently and haven't had time to do practically anything. But with everyones help I managed to get everything working
The way I do It atm is before moving the character it checks the properties of the tile and sees if its solid, etc. and it also checks once its on the tile what it is so it can do things like use health packs, etc.
But I still have a few more issues, the main thing i want to be able to do is to be able to change to tile from code, for example pressing a button changes the tile to a pressed button that doesn't have the solid property and can therefore be walked over.
I've looked into Objects with AdvTiledLoader but I can't make sense of it.
Can someone help please?
The way I do It atm is before moving the character it checks the properties of the tile and sees if its solid, etc. and it also checks once its on the tile what it is so it can do things like use health packs, etc.
But I still have a few more issues, the main thing i want to be able to do is to be able to change to tile from code, for example pressing a button changes the tile to a pressed button that doesn't have the solid property and can therefore be walked over.
I've looked into Objects with AdvTiledLoader but I can't make sense of it.
Can someone help please?
Who is online
Users browsing this forum: Google [Bot] and 6 guests