scene.java

来自「J2ME编程的50个例子,适合掌上系统的编程」· Java 代码 · 共 46 行

JAVA
46
字号
package demo;
import java.io.IOException;
import java.io.InputStream;

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

public class Scene{
	public TiledLayer m_TLayer; 					//场景

	//构造方法
	public Scene(){
		//读取各种场景的tile图像
		try{
			Image image = Image.createImage("/demo/grid.png");
			m_TLayer = new TiledLayer( 20, 5, image, 35, 25 );
		}
		catch(IOException ioe){}
	    catch(Exception e){}
	}
	//读取地图文件
	public void LoadMap(){
		try{
			//读取地图文件
			InputStream is = getClass().getResourceAsStream("/demo/map.txt");
			int ch = -1;
			for( int nRow = 0; nRow < m_TLayer.getRows(); nRow ++ )
			{
				for( int nCol = 0; nCol < m_TLayer.getColumns(); nCol ++ )
				{
					ch = -1;
					while( ( ch < 1 || ch > 4 ) ){
						ch = is.read();
						if( ch == -1 )
							return;
						ch = ch - '0';
					}
					m_TLayer.setCell( nCol, nRow, ch );
				}
			}	
		}
		catch(IOException ioe){}
		catch(Exception e){}
	}

}

⌨️ 快捷键说明

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