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

📄 mytiledlayer.java

📁 Class Wizard to prepare and some commonly used methods, as well as how to use IO to read out the sys
💻 JAVA
字号:
import java.io.IOException;
import java.io.InputStream;

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


public class MyTiledLayer extends TiledLayer
{
	MyTiledLayer(int col,int row,Image img,int tilew,int tileh,String mapname)
	{
		super(col,row,img,tilew,tileh);
		data=loadMap(mapname);

		for(int i=0;i<data.length;i++)
		{
			for(int j=0;j<data[0].length;j++)
			{
				this.setCell(j, i, data[i][j]);
			}
		}
		
		
	}
	 private int writeInt(InputStream is) {
		    int val = 0;
		    try {
		      val |= (is.read() & 0xff) << 0;
		      val |= (is.read() & 0xff) << 8;
		      val |= (is.read() & 0xff) << 16;
		      val |= (is.read() & 0xff) << 24;
		    }
		    catch (IOException ex) {
		      ex.printStackTrace();
		    }
		    return val;
		  }
	  public int[][] loadMap(String name) {
		    InputStream is = "".getClass().getResourceAsStream(name);
		    if (is == null) {
		      System.out.println("can't load map " + name);
		      return null;
		    }

		   int columns = writeInt(is);
		   int rows = writeInt(is);
		    int map[][] = new int[rows][columns];
		    for (int i = 0; i < rows; i++) {
		      for (int j = 0; j < columns; j++) {
		        map[i][j] = writeInt(is);
		      }
		    }
		    return map;
		  }
}

⌨️ 快捷键说明

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