gamethread.java
来自「Source code for j2me game Capture」· Java 代码 · 共 90 行
JAVA
90 行
package cutOff;/** * This class contains the loop that keeps the game running. * * @author Jeremiah McLeod xdebugx */public class GameThread extends Thread { //--------------------------------------------------------- // fields /** * Whether or not this thread has been started. */ boolean myAlreadyStarted; /** * A handle back to the graphical components. */ cutOffCanvas myCutOffCanvas;private long runTime;final int MS_PER_FRAME=25; //---------------------------------------------------------- // initialization /** * standard constructor. */ GameThread(cutOffCanvas canvas) { myCutOffCanvas = canvas; } //---------------------------------------------------------- // actions /** * start or pause or unpause the game. */ void go() { if(!myAlreadyStarted) { myAlreadyStarted = true; start(); } else { } } /** * pause the game. */ void pause() { } /** * stops the game. */ static void requestStop() { } /** * start the game.. */ public void run() { runTime=System.currentTimeMillis(); while(true) { myCutOffCanvas.advance(); long timeSinceStart=(System.currentTimeMillis()-runTime); if (timeSinceStart<MS_PER_FRAME) { try { Thread.sleep(MS_PER_FRAME - timeSinceStart); } catch (java.lang.InterruptedException e) {}}runTime=System.currentTimeMillis();}}}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?