Page 1 of 1
Help with tiles and collisions
Posted: Wed Oct 16, 2013 1:39 am
by PurplePartyGator
Hello. I'm working on creating a platform game as a project for school and everything has been smooth sailing until I get to tile collision. To make my map I used Tiled and to load my map I used the advanced tiled loader library. I'm trying to make my player not be able to just go through the tiles as if nothing were there but instead have the tiles act something like the boundaries I have set for the windows. If anyone could explain to me how I would implement something like this into my game that would be great. here
http://www.mediafire.com/download/n5u85 ... tform.love is my .love file.
Re: Help with tiles and collisions
Posted: Wed Oct 16, 2013 5:36 am
by micha
Welcome to our forum.
First of all, expect the collision to take some time, until you get it right. Collision is not easy.
The general approach is like this. In the update function you change the position of the player. After that you check if there is a collision (collision detection) and if so, then you resolve it by moving the player to a position, where there is no collision.
A tutorial that helped me a lot is this:
Platform Game Programming Tutorial. The collision part is in part 4, but I suggest you read the whole tutorial.
Some thoughts are also on
The guide to implementing 2D platformers.
The method that worked best for me, was to divide movement into x- and y- movement and to do collision that way as well. First move the player only in x-direction. If a collision occurs, then move him back along the x-direction, until the collision is resolved. Then repeat this procedure for the y-direction.