backgroundlayer.java

来自「这是一个用2D来模拟3D效果的卷轴动画 希望大家喜欢!」· Java 代码 · 共 65 行

JAVA
65
字号
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 + =
减小字号Ctrl + -
显示快捷键?