1 / 17
文档名称:

使用MIDP2.0开发游戏.doc

格式:doc   大小:176KB   页数:17页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

使用MIDP2.0开发游戏.doc

上传人:mh900965 2017/12/12 文件大小:176 KB

下载得到文件列表

使用MIDP2.0开发游戏.doc

相关文档

文档介绍

文档介绍:(1)GameCanvas基础
[ 录入者:admin | 时间:2006-05-19 17:35:36 | 作者: |   来源: | 点击数:120 ]
[上一篇] [下一篇]
,,,包括GameCanvas,Sprite,Layer等等。
,我也是初学J2ME不久,准备边看书边做,争取把这个游戏做出来!J2ME高手请多指点,和我一样学****中的朋友欢迎多多交流!
我们的开发环境为Windows XP SP1 + + J2ME + Eclipse + EclipseMe,关于如何配置Eclipse的J2ME开发环境,请参考:
http://blog./mingjava/archive/2004/06/23/
下面是一个最简单的GameCanvas的例子,出自《J2ME  & Gaming》:
//
// 编写Canvas类
import .*;
import .*;
public class MyGameCanvas extends GameCanvas implements Runnable {
    private boolean isPlay; // Game Loop runs when isPlay is true
    private long delay; // To give thread consistency
    private int currentX, currentY; // To hold current position of the 'X'
    private int width; // To hold screen width
    private int height; // To hold screen height
    // Constructor and initialization
    public MyGameCanvas() {
        super(true);
        width = getWidth();
        height = getHeight();
        currentX = width / 2;
        currentY = height / 2;
        delay = 20;
    }
    // Automatically start thread for game loop
    public void start() {
        isPlay = true;
        new Thread(this).start();
    }
    public void stop() { isPlay = false; }
    // Main Game Loop
    public void run() {
        Graphics g = getGraphics();
        while (isPlay) {
            input();
            drawScreen(g);
            try {
                (delay);
            }
            catch (InterruptedException ie) {}
        }
    }
    // Method to Handle User Inputs
    private void input() {
        int keyStates = getKeyStates();
        // Left
        if ((keyStates & LEFT_PRESSED) != 0)
            currentX = (0, currentX - 1);
        // Right
        if ((keyStates & RIGHT_PRESSED) !=0 )