GameCanvas制作动态星空
来源:互联网 发布:cf弹道优化鼠标 编辑:程序博客网 时间:2024/04/28 03:53
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
public class GameCanvas1 extends MIDlet implements CommandListener
{
private Display display;
public static final Command exitCommand = new Command("Exit", Command.EXIT,
1);
public GameCanvas1()
{
}
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()
{
}
protected void startApp() throws MIDletStateChangeException
{
if (display == null)
{
display = Display.getDisplay(this);
initMIDlet();
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.Random;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
// A simple example of a game canvas that displays
// a scrolling star field. Use the UP and DOWN keys
// to speed up or slow down the rate of scrolling.
public class StarField extends GameCanvas implements Runnable
{
private static final int SLEEP_INCREMENT = 10;
private static final int SLEEP_INITIAL = 150;
private static final int SLEEP_MAX = 300;
private Graphics graphics;
private Random random;
private int sleepTime = SLEEP_INITIAL;
private volatile Thread thread;
public StarField()
{
super(true);
graphics = getGraphics();
graphics.setColor(0, 0, 0);
graphics.fillRect(0, 0, getWidth(), getHeight());
}
// The game loop.
public void run()
{
int w = getWidth();
int h = getHeight() - 1;
while (thread == Thread.currentThread())
{
// Increment or decrement the scrolling interval
// based on key presses
int state = getKeyStates();
if ((state & DOWN_PRESSED) != 0)
{
sleepTime += SLEEP_INCREMENT;
if (sleepTime > SLEEP_MAX)
sleepTime = SLEEP_MAX;
} else if ((state & UP_PRESSED) != 0)
{
sleepTime -= SLEEP_INCREMENT;
if (sleepTime < 0)
sleepTime = 0;
}
// Repaint the screen by first scrolling the
// existing starfield down one and painting in
// new stars...
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.sleep(sleepTime);
} catch (InterruptedException e)
{
}
}
}
// When the canvas is shown, start a thread to
// run the game loop.
protected void showNotify()
{
random = new Random();
thread = new Thread(this);
thread.start();
}
// When the game canvas is hidden, stop the thread.
protected void hideNotify()
{
thread = null;
}
}
- GameCanvas制作动态星空
- 使用GameCanvas制作星空效果
- 动态星空web
- 美轮美奂宇宙星空制作神器Spacescape
- 美轮美奂宇宙星空制作神器Spacescape
- [转载]Photoshop背景图制作 : 星空幻想
- GameCanvas.flushGraphics
- GameCanvas类
- 星空
- 星空
- 星空
- canvas鼠标移动动态星空背景特效
- CDR制作壮观的浩瀚宇宙星空实例教程
- 利用GameCanvas的offscreen_buffer
- GameCanvas全屏尺寸的问题
- Pearl 2010(珍珠2010)调光台的灯库制作(by 星空武哥)
- Ps教程:如何用Photoshop制作绚丽的星空字体(一)
- 动态文本的制作
- 使用 Java 生成 MD5 编码
- Excel技术--多级关联菜单相关(OFFSET)
- Excel技术--多级关联菜单相关(MATCH)
- mysql主从复制及读写分离试验
- android中drawable转bitmap的两种方法
- GameCanvas制作动态星空
- QTcreator编译出错
- 使用Spring的SimpleJdbcTemplate完成DAO操作
- Excel技术--二级下拉菜单的3种方法
- Intent 用法集合
- 第一次写这个
- Excel技术--如何合并Excel多个单元格并居中对齐(显示)
- 合并排序算法 C代码
- Oracle RMAN 实践