在SFML中使用图块和冲突检测 [英] 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?
示例:瓷砖
推荐答案
通常使用 sf :: Sprite
绘制图像(sfml1.6)或纹理(sfml2.0).通常的做法是让所有精灵共享相同的tileet纹理/图像,然后使用 sf :: Sprite :: SetSubRect(const IntRect& SubRect)
设置纹理区域应该画出来的.
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.
sfml API中的Sprite类可能是一个很好的起点
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
这篇关于在SFML中使用图块和冲突检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!