这两天重写了sample下面的LunarLander代码,忽然不明白为啥在 LunarView 下面要自己new一个线程来处理呢?既然都是通过while(true){}来画图,那直接在SurfaceView里面搞个循环有啥不可?
对比自己写的一个俄罗斯方块,就是直接继承了SurfaceView,通过Handler做动画处理,没觉得需要new一个线程来处理。
有人能指点迷津或者一起讨论讨论...
Java代码
/**
* View that draws, takes keystrokes, etc. for a simple LunarLander game.
*
* Has a mode which RUNNING, PAUSED, etc. Has a x, y, dx, dy, ... capturing the
* current ship physics. All x/y etc. are measured with (0,0) at the lower left.
* updatePhysics() advances the physics based on realtime. draw() renders the
* ship, and does an invalidate() to prompt another draw() as soon as possible
* by the system.
*/
class LunarView extends SurfaceView implements SurfaceHolder.Callback {
class LunarThread extends Thread {
.........
......
...