【Java开源代码栏目提醒】:网学会员Java开源代码为您提供BackgroundLayer.java参考,解决您在BackgroundLayer.java学习中工作中的难题,参考学习。
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;
}
}
}
上一篇:
BackgroundLabel.java
下一篇:
哈弗F7 VS名爵HS,谁更懂得年轻人的心?