grass.java

来自「用Java/C#开发手机程序及移动应用光盘代码。J2ME核心类及MIDlet类;」· Java 代码 · 共 63 行

JAVA
63
字号
import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;public class Grass extends TiledLayer {	static int TILE_WIDTH = 20;	static int[] FRAME_SEQUENCE = { 2, 3, 2, 4 };	static int COLUMNS;	static int CYCLE = 5;	static int TOP_Y;	int mySequenceIndex = 0;	int myAnimatedTileIndex;	// 计算有多少列	static int setColumns(int screenWidth) {		COLUMNS = ((screenWidth / 20) + 1)*3;		return(COLUMNS);	}	/**	 * 构造方法,其中创建了动态图	 */	public Grass() throws Exception {		super(setColumns(JumpCanvas.DISP_WIDTH), 1, 			Image.createImage("/icons/grass.png"), 			TILE_WIDTH, TILE_WIDTH);		TOP_Y = JumpManager.DISP_HEIGHT - TILE_WIDTH;		setPosition(0, TOP_Y);		myAnimatedTileIndex = createAnimatedTile(2);		for(int i = 0; i < COLUMNS; i++) {			if((i % CYCLE == 0) || (i % CYCLE == 2)) {				setCell(i, 0, myAnimatedTileIndex);			} else {				setCell(i, 0, 1);			}		}	}	/**	 * 重置	 */	void reset() {		setPosition(-(TILE_WIDTH*CYCLE), TOP_Y);		mySequenceIndex = 0;		setAnimatedTile(myAnimatedTileIndex, 			FRAME_SEQUENCE[mySequenceIndex]);	}	/**	 * 步进	 */	void advance(int tickCount) {		if(tickCount % 2 == 0) { // 使其略慢一点			mySequenceIndex++;			mySequenceIndex %= 4;			setAnimatedTile(myAnimatedTileIndex, 				FRAME_SEQUENCE[mySequenceIndex]);		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?