Search code examples
c++collision-detectionsfmltile

Using tiles in SFML and collision detection


I decided to look a good tileset to use and found some, but the question is how I actually load the tile from the image file as there seem to be more than one tile in one file?

Also how do I implement a collision detection for non square tiles?

Example: Tileset


Solution

  • Images(sfml1.6) or Textures (sfml2.0) are usually drawn using sf::Sprite. The usual way to do it is to let all sprites share the same tileset texture/image, and then use sf::Sprite::SetSubRect(const IntRect &SubRect) to set the area of the texture that should be drawn.

    The Sprite class in the sfml API is probably a good place to start