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


Java TMXMapReader.readMap方法代码示例

本文整理汇总了Java中tiled.io.TMXMapReader.readMap方法的典型用法代码示例。如果您正苦于以下问题:Java TMXMapReader.readMap方法的具体用法?Java TMXMapReader.readMap怎么用?Java TMXMapReader.readMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tiled.io.TMXMapReader的用法示例。


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

示例1: loadFromTMX

import tiled.io.TMXMapReader; //导入方法依赖的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

示例2: getCurrentMap

import tiled.io.TMXMapReader; //导入方法依赖的package包/类
private void getCurrentMap () {
    try {
        int hash = MonsterQuestMain.playerStats.mapHash;
        TMXMapReader reader = new TMXMapReader();
        String filepath = (System.getProperty("user.dir") + "%cresources%cmaps%cnewbiesTownCenter_0x0000.tmx");
        String finalFilePath = String.format(filepath, File.separatorChar, File.separatorChar, File.separatorChar);
        Map current = reader.readMap (finalFilePath);
        reloadMap(current);
        
    } catch (Exception ex) {
        systemLog.log("Unable to open tmx file!", Logging.ERROR, ex);
    }
}
 
开发者ID:EhWhoAmI,项目名称:Monster-Quest,代码行数:14,代码来源:MapPainter.java

示例3: Grid2D

import tiled.io.TMXMapReader; //导入方法依赖的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

示例4: main

import tiled.io.TMXMapReader; //导入方法依赖的package包/类
public static void main(String[] arguments) {
    String fileToOpen = null;

    for (String arg : arguments) {
        if ("-?".equals(arg) || "-help".equals(arg)) {
            printHelpMessage();
            return;
        } else if (arg.startsWith("-")) {
            System.out.println("Unknown option: " + arg);
            printHelpMessage();
            return;
        } else if (fileToOpen == null) {
            fileToOpen = arg;
        }
    }

    if (fileToOpen == null) {
        printHelpMessage();
        return;
    }

    Map map;
    try {
        TMXMapReader mapReader = new TMXMapReader();
        map = mapReader.readMap(/*System.getProperty("user.dir") + */fileToOpen);
        System.out.println("Opening " + fileToOpen);
    } catch (Exception e) {
        System.err.println("Error while reading the map:\n" + e.getMessage() + ", Class: " + e.getClass().getName() + " while trying to open " + fileToOpen);
        e.printStackTrace();
        return;
    }

    System.out.println(map.toString() + " loaded");

    JScrollPane scrollPane = new JScrollPane(new MapView(map));
    scrollPane.setBorder(null);
    scrollPane.setPreferredSize(new Dimension(800, 600));

    JFrame appFrame = new JFrame("TMX Viewer");
    appFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    appFrame.setContentPane(scrollPane);
    appFrame.pack();
    appFrame.setVisible(true);
}
 
开发者ID:EhWhoAmI,项目名称:Monster-Quest,代码行数:45,代码来源:TMXViewer.java

示例5: loadFromTMX

import tiled.io.TMXMapReader; //导入方法依赖的package包/类
public MapData loadFromTMX() {
    reader = new TMXMapReader();
    try {
        tiled.core.Map map = reader.readMap(new File("data/maps/" + name + ".tmx").getAbsolutePath());
        map.getLayers().stream().forEach(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 = ((TileLayer) 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.setFilename(fileName);
                    tileData.setSourceX(source.x);
                    tileData.setSourceY(source.y);
                    tileData.setX(x * tile.getWidth());
                    tileData.setY(y * tile.getHeight());
                    tileData.setHasCollision(Boolean.parseBoolean(layer.getProperties().getProperty("collision")));
                    tiles.add(tileData);
                }
            }
        });

        borders.put("borderXLeft", Integer.parseInt(map.getProperties().getProperty("borderXLeft")));
        borders.put("borderXRight", Integer.parseInt(map.getProperties().getProperty("borderXRight")));
        borders.put("borderYDown", Integer.parseInt(map.getProperties().getProperty("borderYDown")));
        borders.put("borderYUp", Integer.parseInt(map.getProperties().getProperty("borderYUp")));
    } catch (Exception e) {
        System.err.println("Couldn't load map data: " + e.getMessage());
        e.printStackTrace();
        System.exit(-1);
    }
    return this;
}
 
开发者ID:Pheelbert,项目名称:cretion,代码行数:61,代码来源:MapData.java


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