游戏结构
来源:互联网 发布:傻瓜进销存软件免费版 编辑:程序博客网 时间:2024/05/16 01:24
MIDlet
public class GameMidlet
extends MIDlet
{
private PlayCanvas play;
public static GameMidlet instance;
public GameMidlet()
{
instance = this;
play=new PlayCanvas(this);
}
protected void pauseApp()
{
}
protected void startApp()
{
Displayable cc=Display.getDisplay(this).getCurrent();
if(cc==null)
Display.getDisplay(this).setCurrent(play);
else
Display.getDisplay(this).setCurrent(cc);
}
protected void destroyApp(boolean parm1)
{
if(play!=null)
play.Release();
play=null;
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
//System.gc();
}
}
canvas:
public class PlayCanvas extends Canvas implements Runnable{
GameMidlet parent;
private boolean running;
private Image imgBody;
private Graphics gBody;
private int TIME=100;
private Thread thread=null;
private width ,height;
public PlayCanvas(GameMidlet parent) {
this.parent = parent;
width = getWidth();
height = getHeight();
imgBody = Image.createImage(width, height); // 缓冲界面
gBody = this.imgBody.getGraphics();
}
/*
线程启动
*/
public void start(){
if(!running){
thread = null;
System.gc();
running=true;
thread=new Thread(this);
thread.start();
}
}
/*
线程停止
*/
public void stop(){
if(running){
running = false;
}
}
/*
按键处理
*/
public void keyPressed(int keyCode) {
switch (keyCode) {
case KEY_UP_ARROW:
. .......................
break;
case KEY_DOWN_ARROW:
. .............
break;
.......................
}
public void paint(Graphics g){
if (imgBody != null) {
g.drawImage(imgBody, 0, 0, Graphics.LEFT | Graphics.TOP); //游戏中的 精灵背景都画在imgBody上。
}
}
public void run(){
while(running){
long start = System.currentTimeMillis();
....... //运行一些逻辑和游戏界面的处理
int time = (int)(System.currentTimeMillis() - start);
if (time < TIME){
try {
Thread.sleep(TIME- time);
}catch (InterruptedException ex) {}
}else{
}
}
}
public void Release(){// 退出游戏 释放对象
thread = null;
imgBody = null;
System.gc();
}
}
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏结构
- 游戏的基础结构。
- 游戏的基础结构
- 游戏的传统结构
- 游戏服务器结构概述
- 一种游戏结构
- 游戏服务器结构探讨
- 再次研究设计模式 第一章 抽象工厂
- .NET 与安全性(1)——— 数据加密算法
- Color类和测试内存的类MemoryMonitor
- 计算字符串中回文的个数。
- 再次研究设计模式 第二章 生成器
- 游戏结构
- SHTML+INC机制说明!
- 通过处理按键模拟加速度,刹车等功能
- 用CSS实现圆角框
- 深入线程的wait()/notify()
- Matlab与VC混合编程
- 奇怪的文件读写程序?
- NAND和NOR flash详解
- Understanding Oracle OLAP Dimensions And Cubes