📄 gamecanvas.java
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public abstract class GameCanvas extends Canvas
{
public static final int UP_PRESSED = 0x0002;
public static final int DOWN_PRESSED = 0x0040;
public static final int LEFT_PRESSED = 0x0004;
public static final int RIGHT_PRESSED = 0x0020;
public static final int FIRE_PRESSED = 0x0100;
public static final int GAME_A_PRESSED = 0x0200;
public static final int GAME_B_PRESSED = 0x0400;
public static final int GAME_C_PRESSED = 0x0800;
public static final int GAME_D_PRESSED = 0x1000;
protected int keyStates;
protected int releasedKeys;
private Image bufferedImage;
private int clipX, clipY, clipWidth, clipHeight;
private boolean setClip;
protected GameCanvas( boolean suppressKeyEvents ) {
super();
this.setFullScreenMode(true);
int width = getWidth();
int height = getHeight();
if(width>=176)
{
if(height<208)
{
height=208;
}
}
this.bufferedImage = Image.createImage( width, height );
}
protected Graphics getGraphics()
{
return this.bufferedImage.getGraphics();
}
public int getKeyStates()
{
int states = this.keyStates;
this.keyStates &= ~this.releasedKeys;
this.releasedKeys = 0;
return states;
}
public void paint( Graphics g)
{
if (this.setClip) {
g.clipRect( this.clipX, this.clipY, this.clipWidth, this.clipHeight);
this.setClip = false;
}
g.drawImage(this.bufferedImage, 0, 0, Graphics.TOP | Graphics.LEFT );
}
public void flushGraphics(int x, int y, int width, int height)
{
this.setClip = true;
this.clipX = x;
this.clipY = y;
this.clipWidth = width;
this.clipHeight = height;
repaint();
serviceRepaints();
}
public void flushGraphics()
{
repaint();
serviceRepaints();
}
protected void keyPressed(int keyCode) {
int gameAction = KeyMapping.getGameKey(keyCode);
if (gameAction != 0) {
int bit = 1 << gameAction;
this.keyStates |= bit;
this.releasedKeys &= ~bit;
}
}
public void setFullScreenMode(boolean enable) {
super.setFullScreenMode(enable);
}
protected void keyReleased(int keyCode) {
int gameAction = KeyMapping.getGameKey(keyCode);
if (gameAction != 0) {
this.releasedKeys |= 1 << gameAction;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -