SFML community forums

Help => Graphics => Topic started by: CowNation on May 01, 2018, 03:48:27 pm

Title: TileMap collision
Post by: CowNation on May 01, 2018, 03:48:27 pm
How would I do collision for a certain texture for my tilemap?
I already have a collision class.
Is there any way to do it without having to set a sprite on top of it?
Am using:
https://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php#example-tile-map
for the tilemap
and am using:
https://github.com/SonarSystems/SFML-Box2D-Tutorials/tree/master/SFML/Tutorial%20013%20-%20Pixel%20Perfect%20Collision%20Detection
for collison class

Thanks in advance
Title: Re: TileMap collision
Post by: Hapax on May 02, 2018, 12:19:00 am
Just keep track of where each of the rectangles are or should be and test against those if the tilemap has a tile of the value that should collide. You can always calculate the rectangles by starting from the tile map's position and adding the x grid position by the tile width and the y grid position by the tile height (both tile sizes multiplied by the tilemap's scale). It's a little more complicated if you've rotated the map though.

Also, the tutorial is for an old version of SFML. Did you realise that? I don't think the tutorial has changed over versions but it's worth noting that you are in 2.1 version of the documentation in case you come across something that has.