Page 1 of 1

Tilemaps and Collisions`

Posted: Wed Nov 23, 2011 12:33 pm
by cryptix
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.

Re: Tilemaps and Collisions`

Posted: Wed Nov 23, 2011 1:02 pm
by Ellohir
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 ;)

Re: Tilemaps and Collisions`

Posted: Wed Nov 23, 2011 2:32 pm
by cryptix
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

Re: Tilemaps and Collisions`

Posted: Wed Nov 23, 2011 7:57 pm
by Kadoba
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:

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
If you don't understand something specific about ATL then let me know and I'll try and help you out.

Re: Tilemaps and Collisions`

Posted: Thu Nov 24, 2011 4:51 am
by Kazagha
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

Re: Tilemaps and Collisions`

Posted: Thu Nov 24, 2011 8:33 am
by kikito
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!

Re: Tilemaps and Collisions`

Posted: Sat Dec 10, 2011 5:32 pm
by cryptix
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?