📄 gamecanvas.java
字号:
/*
* Created on 2005-12-19 by pcy
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package javax.microedition.lcdui.game;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public abstract class GameCanvas extends Canvas {
/**
* The bit representing the UP key. This constant has a value of
* <code>0x0002</code> (1 << Canvas.UP).
*/
public static final int UP_PRESSED = 1 << Canvas.UP;
/**
* The bit representing the DOWN key. This constant has a value of
* <code>0x0040</code> (1 << Canvas.DOWN).
*/
public static final int DOWN_PRESSED = 1 << Canvas.DOWN;
/**
* The bit representing the LEFT key. This constant has a value of
* <code>0x0004</code> (1 << Canvas.LEFT).
*/
public static final int LEFT_PRESSED = 1 << Canvas.LEFT;
/**
* The bit representing the RIGHT key. This constant has a value of
* <code>0x0020</code> (1 << Canvas.RIGHT).
*/
public static final int RIGHT_PRESSED = 1 << Canvas.RIGHT;
/**
* The bit representing the FIRE key. This constant has a value of
* <code>0x0100</code> (1 << Canvas.FIRE).
*/
public static final int FIRE_PRESSED = 1 << Canvas.FIRE;
/**
* The bit representing the GAME_A key (may not be supported on all
* devices). This constant has a value of
* <code>0x0200</code> (1 << Canvas.GAME_A).
*/
public static final int GAME_A_PRESSED = 1 << Canvas.GAME_A;
/**
* The bit representing the GAME_B key (may not be supported on all
* devices). This constant has a value of
* <code>0x0400</code> (1 << Canvas.GAME_B).
*/
public static final int GAME_B_PRESSED = 1 << Canvas.GAME_B;
/**
* The bit representing the GAME_C key (may not be supported on all
* devices). This constant has a value of
* <code>0x0800</code> (1 << Canvas.GAME_C).
*/
public static final int GAME_C_PRESSED = 1 << Canvas.GAME_C;
/**
* The bit representing the GAME_D key (may not be supported on all
* devices). This constant has a value of
* <code>0x1000</code> (1 << Canvas.GAME_D).
*/
public static final int GAME_D_PRESSED = 1 << Canvas.GAME_D;
/**
* Height available to draw on in full screen mode.
*
*/
private int screenWidth;
/**
* Width available to draw on in full screen mode.
*
*/
private int screenHeight;
/**
* currently every GameCanvas has one offscreen buffer
* can be optimized so that we put a limit on no of offscreen buffers
* an application can have
*/
private Image offscreen_buffer;
private boolean suppressKeyEvents;
public GameCanvas(boolean suppressKeyEvents) {
super();
this.suppressKeyEvents=suppressKeyEvents;
screenWidth=getWidth();
screenHeight=getHeight();
offscreen_buffer=Image.createImage(screenWidth,screenHeight);
}
protected Graphics getGraphics(){
return offscreen_buffer.getGraphics();
}
public int getKeyState(){
return 0;
}
public void paint(Graphics g) {
// TODO Auto-generated method stub
g.drawImage(offscreen_buffer,0,0,Graphics.LEFT|Graphics.TOP);
}
public void flushGraphics(int x, int y, int width, int height){
if (width < 1 || height < 1) {
return;
}
repaint(x,y,width,height);
}
public void flushGraphics(){
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -