⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 background.java

📁 Programming java 2 microedition symbian os一书中作者编写的一个赛车游戏的半成品
💻 JAVA
字号:
/*
 * Copyright 2003, 2004 Symbian Ltd.
 * For License terms see http://www.symbian.com/developer/techlib/codelicense.html
 */

package demoracer;

/**
 * <p>Title: DemoRacer</p>
 * <p>Description: Game API Demo for Symbian MIDP 2.0 Book.</p>
 * @author Alan Newman - alan@sensibledevelopment.net
 * @version 1.0
 */


/*
 * This class forms the background layer of the app.
 * it subclasses TiledLayer and creates the tiledlayer from a .png file, called
 * background.png, stored in the JAR.
 * This class is instantiated by RacerLayerManager which is the LayerManager class that manages
 * the animation of the app *
 */
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;

public class Background extends TiledLayer  {
    
    static final int WIDTH=5;
    static final int HEIGHT=5;
    static final int TILE_WIDTH=60;
    static final int TILE_HEIGHT=47;
    
    static int xMove=-2;
    static int yMove=0;
    
    public Background(int columns, int rows, Image image, int tileWidth, int tileHeight) {
        super(columns, rows, image, tileWidth, tileHeight);
        
        // the array which is tile map for the tiledlayer
        int[] map={
            4,4,4,4,4,
            5,5,5,5,5,
            3,3,3,3,3,
            1,2,1,2,1,
            3,3,3,3,3
        };
        
        // insert the tiles in to the tiled later using the setCell() method
        for (int i = 0; i < map.length; i++) {
            int column = i % WIDTH;
            int row = (i - column) / WIDTH;
            setCell(column, row, map[i]);
        }
    }
    
    //The method that moves the tiled layer behind all the other sprites on the display giving the illusion of movement.
    public void tick(){
        move(xMove,yMove);
        if (this.getX() == (this.getCellWidth() * -2)) {
            setPosition(0, 0);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -