使用GameCanvas制作星空效果[2]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

            graphics.copyArea(0, 0, w, h, 0, 1, Graphics.TOP | Graphics.LEFT);
            graphics.setColor(0, 0, 0);
            graphics.drawLine(0, 0, w, 0);
            graphics.setColor(255, 255, 255);
            for (int i = 0; i < w; ++i)
            {
                int test = Math.abs(random.nextInt()) % 100;
                if (test < 5)
                {
                    graphics.drawLine(i, 0, i, 0);
                }
            }
            flushGraphics();

            // Now wait...

            try
            {
                Thread.currentThread().sleep(sleepTime);
            } catch (InterruptedException e)
            {
            }
        }
    }

 

 

 

 

 

 

 

 


下面给出源代码
/*
 * License
 *
 * Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 */

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;

public class GameCanvasTest extends MIDlet implements CommandListener
{

    private Display display;

    public static final Command exitCommand = new Command("Exit", Command.EXIT,
            1);

    public GameCanvasTest()
    {
    }

    public void commandAction(Command c, Displayable d)
    {
        if (c == exitCommand)
        {
            exitMIDlet();
        }
    }

    protected void destroyApp(boolean unconditional)
            throws MIDletStateChangeException
    {
        exitMIDlet();
    }

    public void exitMIDlet()
    {
        notifyDestroyed();
    }

    public Display getDisplay()
    {
        return display;
    }

    protected void initMIDlet()
    {
        GameCanvas c = new StarField();
        c.addCommand(exitCommand);
        c.setCommandListener(this);

        getDisplay().setCurrent(c);
    }

    protected void pauseApp()
    {
    }

本文关键:使用GameCanvas制作星空效果
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top