下面是个简单易学的使用MIDP2.0开发游戏(7)设计Scheduler教程,图老师小编详细图解介绍包你轻松学会,喜欢的朋友赶紧get起来吧!
【 tulaoshi.com - 编程语言 】
以下的Scheduler的实现参考自Marshall "Game Programming Gems 3"中的C++代码:
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)package game.engine.core;
public class Scheduler {
// clock:
private Clock clock = new Clock();
// 启动Scheduler:
public void start() {
clock.start();
}// 停止Scheduler:
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
public void stop() {
clock.stop();
}public int getSystemTime() {
return clock.getSystemTime();
}public int getVirtualTime() {
return clock.getVirtualTime();
}
// 执行完整的一帧:
public void executeFrame() {
System.out.println("-- start execute frame --");
clock.beginFrame();
int started = clock.getSystemTime();
// do time task:
System.out.println("doing time tasks...");
try {
Thread.sleep(500);
}catch(InterruptedException ie) {}
clock.advanceToEnd();
// do frame task:
System.out.println("doing frame tasks...");
try {
Thread.sleep(200);
}catch(InterruptedException ie) {}
// do render task:
int end = clock.getSystemTime();
int elapsed = end - started;
int frameLength = clock.getFrameEnd() - clock.getFrameStart();
System.out.println("elapsed: " + elapsed + ", frame: " + frameLength);
System.out.println("cpu usage: " + (elapsed * 100 / frameLength) + "%");
// cleanup:
System.out.println("-- end execute frame --");
}
来源:http://www.tulaoshi.com/n/20160219/1602719.html
看过《使用MIDP2.0开发游戏(7)设计Scheduler》的人还看了以下文章 更多>>