⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showbullet.java

📁 j2me 小的子弹精灵,简单介绍sprite 的一个例子
💻 JAVA
字号:
package spritebullet;

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

public class ShowBullet
    extends GameCanvas  implements Runnable,CommandListener {
  Bullet bullet;
  Graphics g;
  int x, y, width;

  public ShowBullet(int x, int y, int width) {
    super(true);
    this.x = x;
    this.y = y;
    this.width = width;
    addCommand(new Command("Exit", Command.EXIT, 1));
    setCommandListener(this);
    g = this.getGraphics();
    bullet = new Bullet();
    Thread t = new Thread(this);
    t.start();
  }

  public void commandAction(Command command, Displayable displayable) {
    if (command.getCommandType() == Command.EXIT) {
      MainMIDlet.quitApp();
    }
  }

  public void input() {
    if (getKeyStates() == FIRE_PRESSED) {
      bullet.addBullet(getWidth()/2,getHeight()/2,32);
    }
  }

  public void clear() {
    g.setColor(0, 0, 0);
    g.fillRect(0, 0, this.getWidth(), this.getHeight());
  }

  public void run() {
    while (true) {
      clear();
      input();
      bullet.DrawSelf(g);
      this.flushGraphics();
      bullet.Move();
      try {
        Thread.sleep(100);
      }
      catch (Exception e) {}
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -