使用MIDP1.0实现TiledLayer的效果,并实现简单的…

2008-02-23 09:31:58来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

程序实现的代码如下:

package gamecanvasuse;

import Javax.microedition.lcdui.*;
import com.nokia.mid.ui.FullCanvas;

public class MIDP2Canvas extends FullCanvas {
Image image = null;

int index = 0;
//每个单元使用的图象分块内容
int[][] map = {{0,0,1,3,0,0,0},
{0,1,4,4,3,0,0},
{1,4,4,4,4,3,0},
{0,0,0,0,-1,-1,-1}
};
public MIDP2Canvas() {
//载入图片
try{
image = Image.createImage("/res/title.png");
}catch(Exception e){

}

}


protected void paint(Graphics g) {

for(int i = 0;i < 4;i ){
for(int j = 0;j < 4;j ){
switch (map[j][i index]){
case 0:
g.setColor(0xffffff);
g.fillRect(i * 32,j * 32,32,32);
g.setColor(0x000000);
break;
case 1:
//绘制图块
g.setClip(i * 32,j * 32,32,32);
g.drawImage(image,i * 32,j * 32,Graphics.TOP | Graphics.LEFT);
g.setClip(0,0,this.getWidth(),this.getHeight());
break;
case 2:
//绘制图块
g.setClip(i * 32,j * 32,32,32);
g.drawImage(image,i * 32 - 32,j * 32,Graphics.TOP | Graphics.LEFT);
g.setClip(0,0,this.getWidth(),this.getHeight());
break;
case 3:
//绘制图块
g.setClip(i * 32,j * 32,32,32);
g.drawImage(image,i * 32 - 64,j * 32,Graphics.TOP | Graphics.LEFT);
g.setClip(0,0,this.getWidth(),this.getHeight());
break;
case 4:
//绘制图块
g.setClip(i * 32,j * 32,32,32);
g.drawImage(image,i * 32 - 96,j * 32,Graphics.TOP | Graphics.LEFT);
g.setClip(0,0,this.getWidth(),this.getHeight());
break;
}
}
}

g.setColor(0xff0000);
g.fillRect(32,32,32,32);

g.setColor(0x000000);
}

public void keyPressed(int keyCode){
index ;
repaint();
}

}

上一篇: 推荐三种Java开源报表工具/组件。
下一篇: 使用Lucene进行全文检索(一)---处理索引

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:read-Atleap-3-Tiles学习

下一篇:java.io.ObjectOutput翻译