📄 gamescreen.java
字号:
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class GameScreen extends Canvas implements Runnable{
Image imgRope;
int curFrame;
Image imgBuffer;
public GameScreen(){
try {
imgRope=Image.createImage("/Sprite0_lr.png");
} catch (IOException e) {
}
Thread t=new Thread(this);
t.start();
imgBuffer=Image.createImage(getWidth(),getHeight());
}
protected void paint(Graphics gs) {
Graphics g=imgBuffer.getGraphics();
g.setColor(0xFFFFFF);
int x,y;
x=getWidth()/2-imgRope.getWidth()/7/2;
y=getHeight()/2-imgRope.getHeight()/2;
g.fillRect(0, 0, getWidth(), getHeight());
g.setClip(x, y, imgRope.getWidth()/7, imgRope.getHeight());
g.drawImage(imgRope, -curFrame*imgRope.getWidth()/7+x, y,
20);
curFrame++;
curFrame=curFrame>6?0:curFrame;
System.out.println(isDoubleBuffered());
gs.drawImage(imgBuffer, 0, 0, 20);
}
public void run() {
while(true){
repaint();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -