gamescreen.java

来自「一个小程序,适合参考的原代码」· Java 代码 · 共 49 行

JAVA
49
字号
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 + =
减小字号Ctrl + -
显示快捷键?