Using tiles in SFML and collision detection

匆匆过客 提交于 2019-12-11 08:17:30

问题


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


回答1:


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

  • http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php
  • http://www.sfml-dev.org/documentation/1.6/classsf_1_1Sprite.php


来源:https://stackoverflow.com/questions/10321812/using-tiles-in-sfml-and-collision-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!