SDL:简单位图的 FPS 问题
我目前正在 SDL 中开发一款具有可破坏地形的游戏。目前地形是一张随机生成的大位图(5000*500,用于测试)。
每一帧主表面都会被清除,地形位图会被位图传输到其中。目前的分辨率是1200 * 700,所以当我测试1200 * 500像素时,大部分点都是可见的。
现在的问题是:FPS 已经在下降!我认为一个简单的位图不应该显示任何效果 - 但我已经下降到 ~24 FPS 了!
- 为什么是位块传送 &绘制那么大小的位图这么慢?
我是否在可破坏地形上采取了错误进场?
像《百战天虫》这样的游戏是如何做到这一点的?尽管确实绘制了很多像素,但 FPS 看起来确实很高
I am currently working on a game in SDL which has destructible terrain. At the moment the terrain is one large (5000*500, for testing) bitmap which is randomly generated.
Each frame the main surface is cleared and the terrain bitmap is blitted into it. The current resolution is 1200 * 700, so when I was testing 1200 * 500 pixels were visible at most of the points.
Now the problem is: The FPS are already dropping! I thought one simple bitmap shouldn't show any effect - but I am already falling down to ~24 FPS with this!
- Why is blitting & drawing a bitmap of that size so slow?
Am I taking a false approach at destructible terrain?
How have games like Worms done this? The FPS seem really high although there's definitely a lot of pixels drawn in there
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SDL 中的 2d 速度相当慢,您没有什么办法可以让它更快(在 Windows 上至少它默认使用 GDI 进行绘图)。您的选择是:
2d in SDL is pretty slow and there isn't much you can do to make it faster (on windows at least it uses GDI for drawing by default.) Your options are:
如果你在每一帧重新绘制整个屏幕,你的 FPS 总是很差。您必须仅重画已更改的屏幕部分。您还可以尝试使用 SDL_HWSURFACE 来使用硬件,但它不适用于所有图形卡。
If you redraw the whole screen at each frame your will always get a bad FPS. You have to redraw only part of the screen which have changed. You can also try to use SDL_HWSURFACE to use hardware but it won't work on every graphical card.
每当初始化表面时,请按以下方式执行:
SDL_DisplayFormat() 方法将表面的像素格式转换为视频表面使用的格式。如果您不按照我上面描述的方式执行此操作,SDL 会在每次表面被位块传输时执行此操作。
永远记住:只需位块传输真正对玩家可见的必要部分即可。
这是我的第一个猜测,为什么你会遇到性能问题。如果您需要更多提示,请发布您的代码或提出更具体的问题。祝你游戏顺利。
Whenever you initialize a surface, do it the following way:
The SDL_DisplayFormat() method converts the pixel format of your surface to the format the video surface uses. If you don`t do it the way I described above, SDL does this each time the surface is blitted.
And always remember: just blit the necessary parts that really are visible to the player.
That`s my first guess, why you are having performance problems. Post your code or ask more specific questions, if you want more tipps. Good luck with your game.