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

📄 background.java

📁 《j2me开发精解〉(詹健飞)CD-rom附带源码。用netbeans
💻 JAVA
字号:
package com.j2medev.chapter5.example.hold;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;
import com.j2medev.chapter5.utility.ImageUtilities;

public class Background extends TiledLayer {
    final int AnimatedUpdate_PER_Frame=3;
    int count=0;
    
    static int  map[][] = new int[][] {
        { -1, -1, -1, -2, -2, -2, -1, -1 },
        { -2, 3, 4, -2, -1, -2, -1, -2 },
        { -1, 5, 6, -1, -2, -2, -1, 3 },
        { -2, -2, -1, 7, 8, -2, -2, 5 },
        { -1, -2, -1, 9, 10, -2, -2, -1 },
        { -1, -1, -1, -2, -2, -1, -1, -1 },
        { 7, 8, -2, -1, -2, -2, -2, -2 },
        { 9, 10, -1, -2, -2, -1, -2, -2 }
    };
    
    protected Background(int cols, int rows, Image img, int width, int height) {
        super(cols, rows, img, width, height);
    }
    
    public static Background createBackground() {
        Background bk = new Background(map[0].length, map.length,
                ImageUtilities.createImage("/bk.png"), 32, 32);
        bk.createAnimatedTile(1);
        bk.createAnimatedTile(2);
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[0].length; j++) {
                bk.setCell(j,i,map[i][j]);
            }
        }
        return bk;
    }
    
    public void update(){
        if(count++>AnimatedUpdate_PER_Frame){
            if(getAnimatedTile(-1)!=1)
                setAnimatedTile(-1,1);
            else
                setAnimatedTile(-1,2);
            if(getAnimatedTile(-2)!=1)
                setAnimatedTile(-2,1);
            else
                setAnimatedTile(-2,2);
            count=0;
        }
        
    }
    
}

⌨️ 快捷键说明

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