public class GameMIDlet extends MIDlet { static GameMIDlet instance; Display display; GameDisplayable displayable = null; public GameMIDlet() { instance = this; display = Display.getDisplay(this); displayable = new GameDisplayable(); } public void startApp() { display.setCurrent(displayable); } public void pauseApp() { } public void destroyApp(boolean unconditional) { displayable.running = false; } public static void quitApp() { instance.destroyApp(true); instance.notifyDestroyed(); instance = null; } } public class GameDisplayable extends FullCanvas implements Runnable { /** 主控制线程 */ Thread MainThread = null; /** 游戏时钟间隔 毫秒为单位 */ public static long timeinterval = 20; public static boolean Isstable = true; /* 用于游戏时钟的变量 */ public static long timeold = 0; public static long timenow = 0; public long interval = 0; public static long frames_per_second = 0; int count = 0; long second = 0; public static boolean running = true; public GameDisplayable() { // 开始主线程 Thread MainThread = new Thread(this); MainThread.start(); } public void run() { while (running) { timenow = System.currentTimeMillis(); interval = timenow - timeold; if (interval >= timeinterval) { timeold = timenow; Game_Process(); if (second != (System.currentTimeMillis() / 1000)) { second = System.currentTimeMillis() / 1000; frames_per_second = count; count = 1; } else count++; } lib.sleep(30); } } |
public class GameMIDlet extends MIDlet { GameDisplayable displayable = null; /** 游戏时钟间隔 毫秒为单位 */ public static long timeinterval = 0; //用于游戏时钟的变量 public static long timeold = 0; public static long timenow = 0; public long interval = 0; public static long frames_per_second=0; int count=0; long second =0; public static boolean running = false; static boolean exitApp =false; public GameMIDlet() { displayable = new GameDisplayable(); running =true; } public void startApp() { running =true; Display.getDisplay(this).setCurrent(displayable); while(running) { timenow = System.currentTimeMillis(); interval = timenow - timeold; if (interval >= timeinterval) { timeold = timenow; displayable.Game_Process(); if(second != (System.currentTimeMillis() /1000)){ second = System.currentTimeMillis()/1000; frames_per_second = count; count = 1; }else count ++; } } if(exitApp) { destroyApp(true); notifyDestroyed(); } } public void pauseApp() { running =false; } public void destroyApp(boolean unconditional) { running = false; } public static void quitApp() { running =false; exitApp =true; } } |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |