BackgroundLayer.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
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;
- }
- }
- }