📄 backgroundlayer.java
字号:
import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;/** * A TiledLayer with additional methods for moving it and * keep track of when it has reached its end. * * This code is part of the Tips & Tricks section at * www.SonyEricsson.com/developer * * Written by J鰊s Weimarck, 2004 */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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -