📄 tiledlayer.java
字号:
package CustomlUtil;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public final class TiledLayer
{
public int Height;
public int Width;
public int X;
public int Y;
public int columns;
public int rows;
private Image image[];
private byte tileWidth;
private byte tileHeight;
public int VisibleWidth;
public int VisibleHeight;
private byte TileLayerArray[][];
private Vector v;
public void move(int dx, int dy)
{
X += dx;
Y += dy;
}
public void setPosition(int x, int y)
{
X = x;
Y = y;
}
public TiledLayer(int columns, int rows, Image image, byte tileWidth, byte tileHeight)
{
setStaticTileSet(columns, rows, image, tileWidth, tileHeight);
}
public void setCell(int col, int row, byte tileIndex)
{
TileLayerArray[row][col] = tileIndex;
}
public void setStaticTileSet(int columns, int rows, Image image, byte tileWidth, byte tileHeight)
{
v = new Vector(1,1);
this.columns = columns;
this.rows = rows;
this.image = ImageSet.extractFrames(image, 0, 0,
image.getWidth() / tileWidth, image.getHeight() / tileHeight,
tileWidth, tileHeight);
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
TileLayerArray = new byte[rows][columns];
Width = columns * tileWidth;
Height = rows * tileHeight;
}
public int createAnimatedTile(int staticTileIndex)
{
v.addElement(new Integer(staticTileIndex));
return -v.size();
}
public void setAnimatedTile(int animatedTileIndex, int staticTileIndex)
{
animatedTileIndex++;
v.setElementAt(new Integer(staticTileIndex), -animatedTileIndex);
}
public int getAnimatedTile(int animatedTileIndex)
{
animatedTileIndex++;
return ((Integer)v.elementAt(-animatedTileIndex)).intValue();
}
public void paint(Graphics g)
{
int rowStart = -Y / tileHeight;
int rowEnd = rowStart + VisibleHeight / tileHeight;
int colStart = -X / tileWidth;
int colEnd = colStart + VisibleWidth / tileWidth + 1;
byte index;
int x, y;
for(int i = rowStart; i <= rowEnd; i++)
{
for(int j = colStart; j <= colEnd; j++)
{
if(i < 0 || i >= rows || j < 0 || j >= columns)
{
continue;
}
x = X + j * tileWidth;
y = Y + i * tileHeight;
index = TileLayerArray[i][j];
if(index == 0)
{
continue;
}
else if(index < 0)
{
index = (byte)getAnimatedTile(index);
}
index--;
g.setClip(x, y, tileWidth, tileHeight);
g.drawImage(image[index] , x, y, Configration.G_TL);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -