backgroundlayer.java
来自「J2ME手机游戏开发技术详解随书光盘」· Java 代码 · 共 57 行
JAVA
57 行
import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;public class BackgroundLayer extends TiledLayer{ private int horizontalMove; private int totalPixelLength; public BackgroundLayer(int columns, int rows, Image image, int tileWidth, int tileHeight){ super(columns, rows, image, tileWidth, tileHeight); totalPixelLength = (columns * tileWidth); } /** * Sets the number of pixels to move the layer each * time move() is called */ public void setHorizontalMove(int aHorizontalMove){ horizontalMove = aHorizontalMove; } /** * Moves the background the number of pixels specified with * setHorizontalMove() */ public void move(){ super.move(horizontalMove,0); totalPixelLength += horizontalMove; } /** * Sets the Background's cells according to the information in the passed * parameter int[] aCellMap. * nbrfRows and nbrOfCols refers to the Background's layout */ public void setCells(int[] aCellMap, int nbrOfRows, int nbrOfCols){ for (int i = 0; i < aCellMap.length; i++) { int column = i % nbrOfCols; int row = (i - column) / nbrOfCols; setCell(column, row, aCellMap[i]); } } /** * Returns true if the Background has reached it's end, * false otherwise. */ public boolean endOfBackground(int aScreenWidth){ if (totalPixelLength-aScreenWidth>0){ return false; }else{ return true; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?