📄 midlet6.java
字号:
package prj24_1;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.TiledLayer;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MIDlet6 extends MIDlet {
private MyGameCanvas mgc = new MyGameCanvas();
private Display dis;
protected void startApp() throws MIDletStateChangeException {
dis = Display.getDisplay(this);
dis.setCurrent(mgc);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
class MyGameCanvas extends GameCanvas implements Runnable{
private Image map;
private TiledLayer tlRoad;
private TiledLayer tlWall;
private Graphics gra;
private LayerManager lm;//图层管理器
private boolean RUN = true;
private int Y = 0;
public MyGameCanvas(){
super(true);
try{
map = Image.createImage("/map.png");
gra = this.getGraphics();
tlRoad = new TiledLayer(4,4,map,map.getWidth()/2,map.getHeight());
tlWall = new TiledLayer(4,4,map,map.getWidth()/2,map.getHeight());
lm = new LayerManager();
lm.append(tlRoad);
lm.append(tlWall);
int[][] cells = new int[][]{
{1,2,1,2},
{1,2,2,2},
{1,2,1,2},
{1,2,1,2}
};
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(cells[j][i]==1){
tlRoad.setCell(j, i, cells[i][j]);
}
else{
tlWall.setCell(j, i, cells[i][j]);
}
}
}
}catch(Exception ex){
ex.printStackTrace();
}
new Thread(this).start();
}
public void run(){
while(RUN){
gra.setColor(255,255,255);
gra.fillRect(0,0,this.getWidth(),this.getHeight());
//通过LayerManager显示
lm.setViewWindow(0,Y,80,30);
lm.paint(gra, 30,25); //将图层管理器内的图层画到界面的左上角30,25位置
this.flushGraphics();
Y++;
try{
Thread.currentThread().sleep(100);
}catch(Exception ex){}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -