本文整理汇总了Java中tiled.core.TileLayer.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java TileLayer.getHeight方法的具体用法?Java TileLayer.getHeight怎么用?Java TileLayer.getHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiled.core.TileLayer
的用法示例。
在下文中一共展示了TileLayer.getHeight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translateLayer
import tiled.core.TileLayer; //导入方法依赖的package包/类
/**
* Translate all the tiles of a layer.
*
* @param layer the layer to be translated
*/
private void translateLayer(MapLayer layer) {
if (!(layer instanceof TileLayer)) {
return;
}
TileLayer tileLayer = (TileLayer) layer;
for (int y = 0; y < tileLayer.getHeight(); y++) {
for (int x = 0; x < tileLayer.getWidth(); x++) {
Tile tile = tileLayer.getTileAt(x, y);
if (tile != null) {
tile = translateTile(tile);
tileLayer.setTileAt(x, y, tile);
}
}
}
}
示例2: Grid2D
import tiled.core.TileLayer; //导入方法依赖的package包/类
public Grid2D(String tmxfile, String imageFile) {
super(false, false);
loadTexture(imageFile, true, false);
TMXMapReader reader = new TMXMapReader();
width = 16;
height = 16;
try {
map = reader.readMap(Settings.RESOURCE_PATH + tmxfile);
TileLayer layer = (TileLayer) map.getLayer(0);
mapWidth = layer.getWidth();
mapHeight = layer.getHeight();
byte[][] layerTiles = new byte[mapWidth][mapHeight];
for (int x = 0; x < mapWidth; x++) {
for (int y = 0; y < mapHeight; y++) {
Tile tile = layer.getTileAt(x, y);
if (tile != null) {
layerTiles[x][(mapHeight - 1) - y] = (byte)(tile.getId() + 1);
}
else {
layerTiles[x][y] = 0;
}
}
}
this.tiles = layerTiles;
} catch (Exception e) {
e.printStackTrace();
}
buildMesh();
}
示例3: loadCollisions
import tiled.core.TileLayer; //导入方法依赖的package包/类
private void loadCollisions(TileLayer layer) {
int startX = 0;
int startY = 0;
int endX = layer.getWidth();
int endY = layer.getHeight();
for (int x = startX; x < endX; ++x) {
for (int y = startY; y < endY; ++y) {
Tile tile = layer.getTileAt(x, y);
if (tile == null) continue;
Image image = tile.getImage();
if (image == null) continue;
TileSet tileSet = tile.getTileSet();
TileData tileData = new TileData();
String fileName = tile.getProperties().getProperty("filename");
if (fileName == null) {
String tileBmpFile = tileSet.getTilebmpFile();
int indexOfResources = tileBmpFile.indexOf("resources\\");
fileName = tileBmpFile.substring(indexOfResources);
}
String sourceProperty = tile.getProperties().getProperty("source");
Point source = new Point(0, 0);
if (sourceProperty != null) {
source = parsePoint(sourceProperty);
} else {
int tilesPerRow = tileSet.getTilesPerRow();
int row = tile.getId() % tilesPerRow;
int column = (int)Math.floor(tile.getId() / tilesPerRow);
source = new Point(row * tile.getWidth(), column * tile.getHeight());
}
tileData.filename = fileName;
tileData.sourceX = source.x;
tileData.sourceY = source.y;
tileData.x = x * tile.getWidth();
tileData.y = y * tile.getHeight();
tileData.hasCollision = Boolean.parseBoolean(layer.getProperties().getProperty("collide", "false")); // TODO: Check here if boolean is actually found
tiles.add(tileData);
}
}
}
示例4: paintTileLayer
import tiled.core.TileLayer; //导入方法依赖的package包/类
public void paintTileLayer(Graphics2D g, TileLayer layer) {
final Rectangle clip = g.getClipBounds();
final int tileWidth = map.getTileWidth();
final int tileHeight = map.getTileHeight();
final Rectangle bounds = layer.getBounds();
g.translate(bounds.x * tileWidth, bounds.y * tileHeight);
clip.translate(-bounds.x * tileWidth, -bounds.y * tileHeight);
clip.height += map.getTileHeightMax();
final int startX = Math.max(0, clip.x / tileWidth);
final int startY = Math.max(0, clip.y / tileHeight);
final int endX = Math.min(layer.getWidth(),
(int) Math.ceil(clip.getMaxX() / tileWidth));
final int endY = Math.min(layer.getHeight(),
(int) Math.ceil(clip.getMaxY() / tileHeight));
for (int x = startX; x < endX; ++x) {
for (int y = startY; y < endY; ++y) {
final Tile tile = layer.getTileAt(x, y);
//draw map borders
g.setColor(Color.RED);
if(y == 0) {
g.fillRect(x* tileWidth, (y) * tileHeight - tileHeight,
tileWidth, tileHeight);
}
if(y == (layer.getHeight() -1)) {
g.fillRect(x* tileWidth, (y+2) * tileHeight - tileHeight,
tileWidth, tileHeight);
}
if(x == 0) {
g.fillRect((x-1)* tileWidth, (y + 1) * tileHeight - tileHeight,
tileWidth, tileHeight);
}
if(x == (layer.getWidth()-1)) {
g.fillRect((x+1)* tileWidth, (y + 1) * tileHeight - tileHeight,
tileWidth, tileHeight);
}
if (tile == null)
continue;
final Image image = tile.getImage();
if (image == null)
continue;
g.drawImage(
image,
x * tileWidth,
(y + 1) * tileHeight - image.getHeight(null),
null);
}
}
g.translate(-bounds.x * tileWidth, -bounds.y * tileHeight);
}