一切都很好,并且它适用于中小型迷宫,但是如果我将迷宫单元格大小设置为8像素,则应用程序会在迷宫中抓取大量单元格.
代码正在做一些我不喜欢的事情,即绘制每个单元格,即使它没有改变,这也是为了避免从SurfaceView双缓冲区闪烁屏幕(在应用程序的先前迭代中,我正在绘制的是更改的内容)这导致了一个混乱的混乱).
我想要的是能够使用SurfaceView但是对绘制的内容更具选择性.这可能吗?如果没有,有哪些替代方案?如何保持屏幕外的位图,并选择性地绘制到第一个位图?
编辑:我实现了一个屏幕外的Bitmap和Canvas组合,由我的定时器驱动的状态机写入,只绘制雕刻/解决方案中受影响的区域.然后我简单地将整个屏幕外位图绘制到run()方法中的SurfaceView上,这解决了我的问题;我能够将单元格大小降低到5像素,性能很好.
解决方法
看一下本教程系列.你觉得你画画的方式有什么不同吗?
https://web.archive.org/web/20121109162356/http://www.droidnova.com/playing-with-graphics-in-android-part-iii,176.html
关于优化绘图:
http://developer.android.com/guide/topics/graphics/opengl.html
http://developer.android.com/reference/android/opengl/GLSurfaceView.html
Continuous rendering versus
render-when-dirtyMost 3D
applications,such as games or
simulations,are continuously
animated. But some 3D applications are
more reactive: they wait passively
until the user does something,and
then react to it. For those types of
applications,the default
GLSurfaceView behavior of continuously
redrawing the screen is a waste of
time. If you are developing a reactive
application,you can call
GLSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY),
which turns off the continuous
animation. Then you call
GLSurfaceView.requestRender() whenever
you want to re-render.
此外,在2D游戏中,特别容易计算用户正在看到的内容,因此避免从可见场景中绘制对象.
最后一点:
你说
All well and good and it’s running well for small/medium mazes,however if I set the maze cell size to be 8 pixels there are lots of cells in the maze the application crawls along.
这是否意味着您正在计算迷宫的解决方案?如果是这样,则不应在绘制它的同一个线程中执行此操作.你应该在另一个线程中解决它. (我可能理解你错了)