当前位置: 首页>>代码示例>>Java>>正文


Java TileLayer.getBounds方法代码示例

本文整理汇总了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);
}
 
开发者ID:Pheelbert,项目名称:chatterino,代码行数:40,代码来源:OrthogonalRenderer.java

示例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);
}
 
开发者ID:OpenTiled,项目名称:OpenTiled-Java-Client,代码行数:58,代码来源:OrthogonalRenderer.java

示例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);
}
 
开发者ID:OpenTiled,项目名称:OpenTiled-Java-Client,代码行数:44,代码来源:MapOverlayRenderer.java


注:本文中的tiled.core.TileLayer.getBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。