Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: TileMap collision  (Read 1432 times)

0 Members and 1 Guest are viewing this topic.

CowNation

  • Newbie
  • *
  • Posts: 20
    • View Profile
TileMap collision
« 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

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: TileMap collision
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything