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


Java TileLayer类代码示例

本文整理汇总了Java中tiled.core.TileLayer的典型用法代码示例。如果您正苦于以下问题:Java TileLayer类的具体用法?Java TileLayer怎么用?Java TileLayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TileLayer类属于tiled.core包,在下文中一共展示了TileLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testReadingExampleMap

import tiled.core.TileLayer; //导入依赖的package包/类
public void testReadingExampleMap() throws Exception {
    // Arrange
    File mapFile = getFileFromResources("resources/sewers.tmx");

    // Act
    Map map = new TMXMapReader().readMap(mapFile.getAbsolutePath());

    // Assert
    assertEquals(Map.ORIENTATION_ORTHOGONAL, map.getOrientation());
    assertEquals(50, map.getHeight());
    assertEquals(50, map.getHeight());
    assertEquals(24, map.getTileWidth());
    assertEquals(24, map.getTileHeight());
    assertEquals(3, map.getLayerCount());
    assertNotNull(((TileLayer)map.getLayer(0)).getTileAt(0, 0));
}
 
开发者ID:Pheelbert,项目名称:chatterino,代码行数:17,代码来源:MapReaderTest.java

示例2: testReadingExampleCsvMap

import tiled.core.TileLayer; //导入依赖的package包/类
public void testReadingExampleCsvMap() throws Exception {
    // Arrange
    File mapFile = getFileFromResources("resources/csvmap.tmx");
    
    // Act
    Map map = new TMXMapReader().readMap(mapFile.getAbsolutePath());
    
    // Assert
    assertEquals(Map.ORIENTATION_ORTHOGONAL, map.getOrientation());
    assertEquals(100, map.getHeight());
    assertEquals(100, map.getHeight());
    assertEquals(32, map.getTileWidth());
    assertEquals(32, map.getTileHeight());
    assertEquals(1, map.getLayerCount());
    assertNotNull(((TileLayer)map.getLayer(0)).getTileAt(0, 0));
}
 
开发者ID:Pheelbert,项目名称:chatterino,代码行数:17,代码来源:MapReaderTest.java

示例3: loadFromTMX

import tiled.core.TileLayer; //导入依赖的package包/类
public MapData loadFromTMX() {
  reader = new TMXMapReader();
  try {
    File mapFile = new File("data/maps/" + name + ".tmx");
    String mapFileAbsolutePath = mapFile.getAbsolutePath();
    Log.info("Loading " + mapFileAbsolutePath);
    tiled.core.Map map = reader.readMap(mapFileAbsolutePath);
    map.getLayers().stream().forEach(layer -> {
      if (layer.getName().equals("image")) {
        loadMapImage(layer);
      } else if (layer.getName().equals("collisions")) {
        loadCollisions((TileLayer)layer);
      } else {
        Log.warn("Ignored unexpected layer in .tmx file: " + layer.getName());
      }
    });
  } catch (Exception e) {
    Log.error("Couldn't load map data: " + e.getMessage());
    e.printStackTrace();
    System.exit(-1);
  }
  return this;
}
 
开发者ID:Pheelbert,项目名称:chatterino,代码行数:24,代码来源:MapData.java

示例4: loadPhoto

import tiled.core.TileLayer; //导入依赖的package包/类
public void loadPhoto () {
        try{
            Rectangle clip = new Rectangle(map.getWidth() * map.getTileWidth(), map.getWidth()* map.getTileHeight());
            BufferedImage toWrite = new BufferedImage(clip.width, clip.width, BufferedImage.TYPE_INT_RGB);
            Graphics2D gd = toWrite.createGraphics();
            
            gd.setClip(clip);
            // Draw a gray background
            gd.setPaint(new Color(100, 100, 100));
            gd.fill(clip);
            
            // Draw each tile map layer
            for (MapLayer layer : map) {
                if (layer instanceof TileLayer) {
                    renderer.paintTileLayer(gd, (TileLayer) layer);
                }
            }
            
            
            ImageIO.write(toWrite, "PNG", new File("test.png"));
//            BufferedImage toPut = ImageIO.read(new File ("test.png"));
//            g2d.drawImage(toPut, 0, 0, null);
        } catch (IOException ex) {
            Logger.getLogger(MapView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
开发者ID:EhWhoAmI,项目名称:Monster-Quest,代码行数:27,代码来源:TMXViewer.java

示例5: paint

import tiled.core.TileLayer; //导入依赖的package包/类
@Override
public void paint(Graphics g) {
    getCurrentMap();
    final Graphics2D g2d = (Graphics2D) g.create();
    final Rectangle clip = g2d.getClipBounds();
    systemLog.log(clip.toString());
    // Draw a gray background
    g2d.setPaint(new Color(100, 100, 100));
    g2d.fill(clip);
    systemLog.log("Loading " + map.getLayerCount() + " layers.");
    // Draw each tile map layer
    for (MapLayer layer : map) {
        if (layer instanceof TileLayer) {
            renderer.paintTileLayer(g2d, (TileLayer) layer);
        }
    }
    
}
 
开发者ID:EhWhoAmI,项目名称:Monster-Quest,代码行数:19,代码来源:MapPainter.java

示例6: updateFromServer

import tiled.core.TileLayer; //导入依赖的package包/类
public static void updateFromServer(String update, TileLayer layer) {
	if(update.isEmpty())
		return;
	
	JSONObject data = new JSONObject(update);
	if(!data.isNull("mapchange")) {
		try {
			JSONObject mapchange = data.getJSONObject("mapchange");
			int x = mapchange.getInt("x");
			int y = mapchange.getInt("y");
			int tileID = mapchange.getInt("tileID");
			//There seems to be a bug with the id of the first tile
			tileID = tileID > 0 ? tileID-1 : tileID;   
			layer.setTileAt(x, y, layer.getMap().getTileSets().get(0).getTile(tileID));
		} catch(JSONException e) {
			System.out.println("Malformed JSON " + e.getMessage());
			e.printStackTrace();
		}
	}
}
 
开发者ID:OpenTiled,项目名称:OpenTiled-Java-Client,代码行数:21,代码来源:Window.java

示例7: paintComponent

import tiled.core.TileLayer; //导入依赖的package包/类
@Override
public void paintComponent(Graphics g) {
	final Graphics2D g2d = (Graphics2D) g.create();
       final Rectangle clip = g2d.getClipBounds();
       // Draw a gray background
       g2d.setPaint(new Color(100, 100, 100));
       g2d.fill(clip);
       g2d.translate(x, y);
       // Draw each tile map layer
       for (MapLayer layer : map) {
           if (layer instanceof TileLayer) {
               renderer.paintTileLayer(g2d, (TileLayer) layer);
               //mapOverlay.paintTileLayer(g2d, (TileLayer) layer);
           }
       }
}
 
开发者ID:OpenTiled,项目名称:OpenTiled-Java-Client,代码行数:17,代码来源:MapView.java

示例8: 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

示例9: 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

示例10: 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

示例11: isUsedTileset

import tiled.core.TileLayer; //导入依赖的package包/类
/**
 * Check whether a tileset is in use by a map.
 * 
 * @param map the map to be checked
 * @param tileset the tileset to be checked
 * @return true iff the tileset is in use
 */
private boolean isUsedTileset(final Map map, final TileSet tileset) {
	for (final Iterator< ? > tiles = tileset.iterator(); tiles.hasNext();) {
		final Tile tile = (Tile) tiles.next();

		for (final MapLayer layer : map) {
			if ((layer instanceof TileLayer) && (((TileLayer) layer).isUsed(tile))) {
				return true;
			}
		}
	}

	return false;
}
 
开发者ID:arianne,项目名称:stendhal,代码行数:21,代码来源:TilesetConverter.java

示例12: isUsedTileset

import tiled.core.TileLayer; //导入依赖的package包/类
private boolean isUsedTileset(final Map map, final TileSet tileset) {
	for (final Iterator< ? > tiles = tileset.iterator(); tiles.hasNext();) {
		final Tile tile = (Tile) tiles.next();

		for (final MapLayer layer : map) {
			if ((layer instanceof TileLayer) && (((TileLayer) layer).isUsed(tile))) {
				return true;
			}
		}
	}

	return false;
}
 
开发者ID:arianne,项目名称:stendhal,代码行数:14,代码来源:MapUpdater.java

示例13: 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

示例14: 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

示例15: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。