2008-06-30
游戏主线程
该游戏的主线程处于继续自Canvas有类中:
/**
* 游戏线程
*/
// 每33毫秒一个循环(即每秒24帧)
private final static int MIN_LOOP_TIME = 33;
// 每5步刷新一次屏幕
private final static int MIN_REPAINT_LOOP = 5;
public final void run() {
Thread.currentThread().setPriority(1);
time = System.currentTimeMillis();
try {
while (true) {
//... 部分省略
viewMan.go();//viewMan是视图控制器,由它控制游戏的进行。
// 一般情况下循环MIN_REPAINT_LOOP次才刷新屏幕
// 有刷新要求除外
if (needRepaint || loops > MIN_REPAINT_LOOP) {
repaint();
serviceRepaints();
loops = 0;
} else {
loops++;
}
//nowStep++;
// 保证一次循环最少要有MIN_LOOP_TIME,若不足则加入延时
long l = (time + MIN_LOOP_TIME) - System.currentTimeMillis();
if (l > (long) 0) {
synchronized (this) {
wait(l);
}
// 延时后要对屏幕进行刷新
needRepaint = true;
} else {
needRepaint = false;
}
time += MIN_LOOP_TIME;
}
} catch (InterruptedException interruptedexception) {
}
}
- 22:06
- 浏览 (176)
- 评论 (0)
- 分类: 学习 PillsAnd Thrills 心得
- 发布在 j2me圈子 圈子
- 相关推荐
发表评论
- 浏览: 13758 次
- 性别:

- 来自: 广州

- 详细资料
搜索本博客
我的相册
jaccount1.0.7
共 5 张
共 5 张
最近加入圈子
链接
最新评论
-
Java 初学者应对以下代码 ...
~呵呵,测试了下你的留言版,不太行哦!~~~
-- by ggweixudong -
Java 初学者应对以下代码 ...
[list=1] [*][list=1] [*][*][list=1] [*] ...
-- by ggweixudong -
能否考虑使用asp实现服务 ...
那就要研究一下asp了,不知道又要花我多长时间呢?干吧,管它呢!
-- by iwinyeah -
能否考虑使用asp实现服务 ...
当然是可以的。而且这些东西,用http协议搞下就OK了。很简单的。
-- by wuhua -
试翻译Openbasemovil-core ...
很不错哦,值得期待。
-- by LinuxFans






评论排行榜