本文整理汇总了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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}