本文整理汇总了Java中tiled.core.TileLayer.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TileLayer.getBounds方法的具体用法?Java TileLayer.getBounds怎么用?Java TileLayer.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiled.core.TileLayer
的用法示例。
在下文中一共展示了TileLayer.getBounds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
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);
}
示例2: 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);
}
示例3: 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));
Color prevColor = null;
for (int x = startX; x < endX; ++x) {
for (int y = startY; y < endY; ++y) {
final Tile tile = layer.getTileAt(x, y);
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);*/
prevColor = g.getColor();
g.setColor(Color.green);
g.drawRect(x * tileWidth, (y + 1) * tileHeight - image.getHeight(null),
image.getWidth(null), image.getWidth(null));
}
}
g.setColor(prevColor);
g.translate(-bounds.x * tileWidth, -bounds.y * tileHeight);
}