• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TMXMapReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TMXMapReader类属于tiled.io包,在下文中一共展示了TMXMapReader类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: convert

import tiled.io.TMXMapReader; //导入依赖的package包/类
/** converts the map files.
 * @param tmxFile
 * @throws Exception */
public void convert(final String tmxFile) throws Exception {
	final File file = new File(tmxFile);

	final String filename = file.getAbsolutePath();
	final Map map = new TMXMapReader().readMap(filename);
	saveImageMap(map, tmxFile);
}
 
开发者ID:arianne,项目名称:stendhal,代码行数:11,代码来源:MapRenderer.java


示例5: convert

import tiled.io.TMXMapReader; //导入依赖的package包/类
/** 
 * Converts a map file according to the tile mapping.
 *  
 * @param tmxFile the map to be converted
 * @throws Exception
 */
private void convert(final String tmxFile) throws Exception {
	final File file = new File(tmxFile);

	final String filename = file.getAbsolutePath();
	final Map map = new TMXMapReader().readMap(filename);
	addNewTilesets(map);
	translateMap(map);
	removeUnusedTilesets(map);
	new TMXMapWriter().writeMap(map, filename);
}
 
开发者ID:arianne,项目名称:stendhal,代码行数:17,代码来源:TilesetConverter.java


示例6: convert

import tiled.io.TMXMapReader; //导入依赖的package包/类
/** Converts the map files. 
 * @param tmxFile 
 * @throws Exception */
public void convert(final String tmxFile) throws Exception {
	final File file = new File(tmxFile);

	final String filename = file.getAbsolutePath();
	final Map map = new TMXMapReader().readMap(filename);
	removeUnusedTilesets(map);
	removeUnusedLayers(map);
	new TMXMapWriter().writeMap(map, filename);
}
 
开发者ID:arianne,项目名称:stendhal,代码行数:13,代码来源:MapUpdater.java


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


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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Hierarchy类代码示例发布时间:2022-05-22
下一篇:
Java Phased类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap