日期:2014-05-20 浏览次数:20909 次
public class LiangZi2 extends MIDlet {
private Display dis;
private MyGameCanvas mgc=new MyGameCanvas();
protected void startApp() throws MIDletStateChangeException {
dis=Display.getDisplay(this);
dis.setCurrent(mgc);
}
class MyGameCanvas extends GameCanvas implements Runnable{
private Image LiangZi,imageYouli;
private TiledLayer BackGroundCanvas;
private Graphics gra;
private LayerManager lm;
private Sprite spriteYouli;
private boolean RUN=true;
public MyGameCanvas(){
super(true);
Mydebug(1);
try
{
LiangZi=Image.createImage("/Img6.jpg");
imageYouli=Image.createImage("/youlishuping.png");
//LiangZi=Image.createImage("/123.gif");
gra=this.getGraphics();
//spriteZuoquan=new Sprite(zuoquan);
//spriteYouquan=new Sprite(youquan);
spriteYouli=new Sprite(imageYouli,imageYouli.getWidth(),imageYouli.getHeight()/41);
BackGroundCanvas=new TiledLayer(1,1,LiangZi,LiangZi.getWidth(),
LiangZi.getHeight()/3);
lm=new LayerManager();
lm.append(BackGroundCanvas);
BackGroundCanvas.setCell(0,0, 1);
//Sleep(3000);
}
catch(Exception ex){ex.printStackTrace();}
Mydebug(4);
new Thread(this).start();
}
public void run() {
int scrWidth=0,scrHeight=0;
scrWidth=this.getWidth();
scrHeight=this.getHeight();
Mydebug(2);
//spriteZuoquan.setPosition(65,128);
//spriteYouquan.setPosition(195,128);
spriteYouli.setPosition(-80,30);
while (RUN)
{
gra.setColor(0xFFFFFF);
gra.fillRect(0, 0,scrWidth,scrHeight);
lm.paint(gra,0,0);
spriteYouli.paint(gra);
//左右拳显示
// spriteZuoquan.paint(gra);
// spriteYouquan.paint(gra);
this.flushGraphics();
spriteYouli.nextFrame();
try{
Thread.currentThread();
Thread.sleep(100);
}catch(Exception ex){System.out.println("Sleep error");}
/*BackGroundCanvas.setCell(0, 0, iNext);
iNext++;
if(iNext>3)
iNext=1;*/
//Mydebug(iNext);
}
}
}
public void Sleep(long time){
try{
Thread.currentThread();
Thread.sleep(time);
}catch(Exception ex){System.out.println("Sleep error");}
}
protected void Mydebug(int i){
System.out.println("到达"+i);
}
public LiangZi2() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
}
}