gamelayermger.java

来自「一个用于熟悉J2ME和Nokia SDK开发游戏的例子」· Java 代码 · 共 59 行

JAVA
59
字号
/* This file was created by Carbide.j */
package gamenokia;

import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.Image;

public class gameLayerMger extends LayerManager
{
     javax.microedition.lcdui.game.TiledLayer layer1;
     javax.microedition.lcdui.Image layer1_tiles;

     public gameLayerMger()
     {
          super();
          try
          {
               ndsInit();
          }
          catch (Exception e)
          {
          }
     }

     void ndsInit() throws Exception
     {
          layer2_tiles = Image.createImage("/images/example_tile_palette.png");
          layer2 = new TiledLayer(10, 10, layer2_tiles, 24, 35);
          layer2.setPosition(0, 0);
          layer1_tiles = Image.createImage("/images/example_tile_palette.png");
          layer1 = new TiledLayer(10, 10, layer1_tiles, 24, 35);
          layer1.setPosition(0, 0);
          fillLayer(layer2, layer2_cells);
          fillLayer(layer1, layer1_cells);
          append(layer1);
          append(layer2);
     }

     javax.microedition.lcdui.game.TiledLayer layer2;
     javax.microedition.lcdui.Image layer2_tiles;
     int[] layer2_cells = new int[] { 118, 118, 117, 31, 31, 31, 85, 46, 46, 46, 31, 31, 103, 31, 31, 134, 28, 46, 46,
          46, 31, 31, 103, 31, 31, 31, 31, 28, 46, 46, 31, 31, 103, 31, 31, 31, 31, 134, 28, 30, 31, 31, 103, 31, 31,
          31, 31, 31, 134, 31, 31, 31, 103, 31, 31, 31, 31, 31, 31, 31, 96, 96, 101, 96, 96, 96, 96, 96, 96, 96, 31, 31
          , 103, 31, 31, 133, 31, 134, 31, 31, 31, 31, 104, 118, 118, 118, 118, 115, 130, 31, 31, 31, 31, 31, 31, 31,
          31, 133, 31, 31 };
     int[] layer1_cells = new int[] { 0, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, 0,
          0, 127, 0, 0, 0, 0, 131, 0, 0, 131, 0, 127, 0, 0, 0, 0, 0, 0, 127, 0, 127, 0, 0, 0, 0, 0, 0, 0, 132, 127, 132
          , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 124, 0, 112, 0, 0, 0, 0, 0, 0, 124, 124, 0, 0, 0, 0, 0, 0, 0
          , 0, 0, 124, 112, 0, 0, 124, 0, 0, 0, 0 };
     void fillLayer(TiledLayer layer, int[] cells)
     {
          for ( int row = 0; row < layer.getRows(); row++)
          {
               for ( int col = 0; col < layer.getColumns(); col++)
               {
                    layer.setCell(col, row, cells[row * layer.getColumns() + col]);
               }
          }
     }
}

⌨️ 快捷键说明

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