为什么我的 SurfaceView 的游戏循环无法运行良好的 FPS?
我拼凑了一个简单的游戏循环,主要使用似乎流行的技术,特别是在《Java 杀手游戏编程》一书中以及在本教程中我刚刚发现的: 这里 只是一个带有后台缓冲区的简单定时游戏循环。
问题是它不会以良好的 FPS 重绘屏幕。我能从我的摩托罗拉 Xoom 中获得的最佳帧率是 15FPS,目标是 24。
如果我将后台缓冲区的大小减半,速度会显着提高,所以我猜测问题可能与使用屏幕上的屏幕有关。 Xoom(我的 SurfaceView 的大小是 1280x727)...但其他游戏在相同大小下运行得非常好。
我没有任何其他设备可以测试,所以我现在有点不知所措。
我做错了什么/遗漏/不知道什么?
I've cobbled together a simple game loop, mostly using the techniques that seem be be prevelent, particually in the Killer Game Programming in Java book and in this tutorial I just found: Here
Just a simple, timed gameloop with a back buffer.
The problem is that it won't redraw the screen at a good FPS. The best I can get out of my Motorola Xoom is 15FPS, aiming for 24.
If I half the size of the back buffer, the speed shoots up considerably so I'm guesing the problem may have something to do with utilizing the screen on the Xoom ( the size of my SurfaceView is 1280x727 )... yet other games seen to run perfectly well at the same size.
I don't have any other devices to test on so I'm a little stuck for what to do at the moment.
What am I doing wrong/missing/ignorant of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许位图和表面的像素格式不同,导致每次绘制位图时都会发生转换?这肯定会产生开销。尝试使用 SurfaceHolder.setFormat()看看是否有帮助。
由于您的位图使用的是
Bitmap.Config.ARGB_8888
,因此您可以尝试将表面支架格式设置为PixelFormat.RGBA_8888
。或者,如果可以的话,请尝试使用Bitmap.Config.RGB_565
和PixelFormat.RGB_565
。Maybe that the pixel formats of your bitmap and the surface differ, causing a conversion whenever you draw the bitmap? That would certainly induce overhead. Try and experiment with SurfaceHolder.setFormat() to see if that helps.
Since your bitmap is using
Bitmap.Config.ARGB_8888
, you could try to set the surface holder format toPixelFormat.RGBA_8888
. Or, if you can, then try and useBitmap.Config.RGB_565
, andPixelFormat.RGB_565
.需要一些代码,但我怀疑您没有使用任何线程?如果你不使用线程,那么你的程序将不稳定并且经常崩溃,因为你的所有处理都在同一个线程上
简而言之,确保你已经创建了一个新线程,我使用OpenGL,它无论如何都需要一个线程,所以这可能是你的下山的最佳路线
Going to need some code but I suspect you are not using any threads? If you are not using Threads then you program will be unstable and crash quite often due to all your processing being on the same Thread
In short make sure you have created a new Thread, I use OpenGL which requires a thread anyway so that may be your best route to go down