WEB开发网
开发学院手机开发Android 开发 Android LunarLander LunarView new一个线程的意义... 阅读

Android LunarLander LunarView new一个线程的意义何在

 2010-08-21 06:15:00 来源:WEB开发网   
核心提示:这两天重写了sample下面的LunarLander代码,忽然不明白为啥在 LunarView 下面要自己new一个线程来处理呢?既然都是通过while(true){}来画图,Android LunarLander LunarView new一个线程的意义何在,那直接在SurfaceView里面搞个循环有啥不可?对比自

这两天重写了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 {

.........

......

...

Tags:Android LunarLander LunarView

编辑录入:coldstar [复制链接] [打 印]
赞助商链接