Tile引擎性能问题
我正在使用 SFML,但找不到有关该库如何工作的任何解释,并且存在性能问题。 我正在尝试制作由 50x50 瓷砖组成的瓷砖地图,每个瓷砖宽度为 20x20 像素。 1)每个图块都是一个 sf::sprite,其图形图像只是一个大图像(我的图块集),我在其上设置了一个 20x20 子矩形。 2)我只是循环遍历图块总数并使用 App.Draw(Map[i][j]);绘制每个图块,我使用“视图”对象,这样我就可以移动视图
现在我的 FPS 非常低(1 个图像/秒),我想知道与前面的点相关的两件事。 1)每个 sf::sprite 是否需要时间来绘制,因为它们的图像来自被裁剪的巨大图像? 2)我是否可以循环遍历整组图块,甚至是那些我没有看到的图块?我假设视图对象使得视图之外的图块不会被徒劳地重新计算,
谢谢
I am using SFML and I can't find any explanation on how the library is working and I have performance issues.
I am trying to make a tile map made of 50x50 tiles that are each 20x20 pixels wide.
1) Each tile is a sf::sprite whose graphic image is simply a big image (my tileset), on which I set a 20x20 subrectangle.
2) I am simply looping over total number of tiles and using App.Draw(Map[i][j]); to draw each tile, and I am using "view" objects so I can move the view around
Now I have a very low FPS (1 image / second) and I am wondering 2 things in relation to the previous points.
1) Is it that each sf::sprite takes time to draw because their image is coming from a huge image that was cropped?
2) Am I right to loop over the whole set of tiles, even the ones I am not seeing? I am assuming that the view object makes it so that the tiles that are out of view are not re-computed in vain
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这通常被认为是渲染图块地图的错误方法。
更正确的方法是创建一个大纹理,或者在本例中为 sf::Image,然后将图块渲染到该纹理上,然后将这个大纹理渲染到屏幕上。在某些情况下,这种方法不可行,但对于大多数情况,它要好得多。
这样,在加载图块贴图时,您只需渲染每个图块一次,然后只需为每个帧渲染一次大纹理,而不是为每个帧渲染 2500 个单独的图块。
SFML 使用 OpenGL 的方式对于大量
Draw()
调用并不友好,因此有助于找到尽可能少地调用它的方法。This is generally considered the wrong way to render a tile map.
The more correct way is to create a large texture, or
sf::Image
in this case, and then rendering your tiles onto this texture, and then rendering this large texture to the screen. There are cases where this approach isn't feasible, but for most cases, it's much better.This way, you only render each tile once when the tile map is loaded, and then you only need to render the large texture once for each frame, as opposed to rendering 2500 individual tiles for each frame.
The way SFML uses OpenGL isn't friendly to large numbers of
Draw()
calls, so it helps to find ways to call it as few times as possible.