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


Java TileLayer.getHeight方法代码示例

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

示例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();
}
 
开发者ID:pianoman373,项目名称:Point-Engine,代码行数:37,代码来源:Grid2D.java

示例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);
    }
  }
}
 
开发者ID:Pheelbert,项目名称:chatterino,代码行数:45,代码来源:MapData.java

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


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