<map>

  • version: The TMX format version, generally 1.0.
  • orientation: Map orientation. Tiled supports "orthogonal", "isometric" and "staggered" (since 0.9.0) at the moment.
  • width: The map width in tiles.
  • height: The map height in tiles.
  • tilewidth: The width of a tile.
  • tileheight: The height of a tile.
  • backgroundcolor: The background color of the map. (since 0.9.0)

The tilewidth and tileheight properties determine the general grid size of the map. The individual tiles may have different sizes. Larger tiles will extend at the top and right (anchored to the bottom left).

Can contain: properties, tileset, layer, objectgroup, imagelayer

<tileset>

  • firstgid: The first global tile ID of this tileset (this global ID maps to the first tile in this tileset).
  • source: If this tileset is stored in an external TSX (Tile Set XML) file, this attribute refers to that file. That TSX file has the same structure as the attribute as described here. (There is the firstgid attribute missing and this source attribute is also not there. These two attributes are kept in the TMX map, since they are map specific.)
  • name: The name of this tileset.
  • tilewidth: The (maximum) width of the tiles in this tileset.
  • tileheight: The (maximum) height of the tiles in this tileset.
  • spacing: The spacing in pixels between the tiles in this tileset (applies to the tileset image).
  • margin: The margin around the tiles in this tileset (applies to the tileset image).

Can contain: tileoffset (since 0.8.0), properties (since 0.8.0), image, terraintypes (since 0.9.0), tile

<tileoffset>

  • x: Horizontal offset in pixels
  • y: Vertical offset in pixels (positive is down)

This element is used to specify an offset in pixels, to be applied when drawing a tile from the related tileset. When not present, no offset is applied.

<image>

  • format: Used for embedded images, in combination with a data child element. (since 0.9.0)
  • id: Used by some versions of Tiled Java. Deprecated and unsupported by Tiled Qt.
  • source: The reference to the tileset image file (Tiled supports most common image formats).
  • trans: Defines a specific color that is treated as transparent (example value: "FF00FF" for magenta).
  • width: The image width in pixels (optional, used for tile index correction when the image changes)
  • height: The image height in pixels (optional)

As of the current version of Tiled Qt, each tileset has a single image associated with it, which is cut into smaller tiles based on the attributes defined on the tileset element. Later versions may add support for adding multiple images to a single tileset, as is possible in Tiled Java.

Can contain: data (since 0.9.0)

<terraintypes>

This element defines an array of terrain types, which can be referenced from the terrain attribute of the tile element.

Can contain: terrain

<terrain>

  • name: The name of the terrain type.
  • tile: The local tile-id of the tile that represents the terrain visually.

Can contain: properties

<tile>

  • id: The local tile ID within its tileset.
  • terrain: Defines the terrain type of each corner of the tile, given as comma-separated indexes in the terrain types array in the order top-left, top-right, bottom-left, bottom-right. Leaving out a value means that corner has no terrain. (optional) (since 0.9.0)
  • probability: A percentage indicating the probability that this tile is chosen when it competes with others while editing with the terrain tool. (optional) (since 0.9.0)

Can contain: properties, image (since 0.9.0)

<layer>

All <tileset> tags shall occur before the first <layer> tag so that parsers may rely on having the tilesets before needing to resolve tiles.

  • name: The name of the layer.
  • x: The x coordinate of the layer in tiles. Defaults to 0 and can no longer be changed in Tiled Qt.
  • y: The y coordinate of the layer in tiles. Defaults to 0 and can no longer be changed in Tiled Qt.
  • width: The width of the layer in tiles. Traditionally required, but as of Tiled Qt always the same as the map width.
  • height: The height of the layer in tiles. Traditionally required, but as of Tiled Qt always the same as the map height.
  • opacity: The opacity of the layer as a value from 0 to 1. Defaults to 1.
  • visible: Whether the layer is shown (1) or hidden (0). Defaults to 1.

Can contain: properties, data

<data>

  • encoding: The encoding used to encode the tile layer data. When used, it can be "base64" and "csv" at the moment.
  • compression: The compression used to compress the tile layer data. Tiled Qt supports "gzip" and "zlib".

When no encoding or compression is given, the tiles are stored as individual XML tile elements. Next to that, the easiest format to parse is the "csv" (comma separated values) format.

The base64-encoded and optionally compressed layer data is somewhat more complicated to parse. First you need to base64-decode it, then you may need to decompress it. Now you have an array of bytes, which should be interpreted as an array of unsigned 32-bit integers using little-endian byte ordering.

Whatever format you choose for your layer data, you will always end up with so called "global tile IDs" (gids). They are global, since they may refer to a tile from any of the tilesets used by the map. In order to find out from which tileset the tile is you need to find the tileset with the highest firstgid that is still lower or equal than the gid. The tilesets are always stored with increasing firstgids.

Can contain: tile

Tile flipping

When you use the tile flipping feature added in Tiled Qt 0.7.0, the highest two bits of the gid store the flipped state. Bit 32 is used for storing whether the tile is horizontally flipped and bit 31 is used for the vertically flipped tiles. And since Tiled Qt 0.8.0, bit 30 means whether the tile is flipped (anti) diagonally, enabling tile rotation. These bits have to be read and cleared before you can find out which tileset a tile belongs to.

When rendering a tile, the order of operation matters. The diagonal flip (x/y axis swap) is done first, followed by the horizontal and vertical flips.

The following C++ pseudo-code should make it all clear:

// Bits on the far end of the 32-bit global tile ID are used for tile flags
const unsigned FLIPPED_HORIZONTALLY_FLAG = 0x80000000;
const unsigned FLIPPED_VERTICALLY_FLAG = 0x40000000;
const unsigned FLIPPED_DIAGONALLY_FLAG = 0x20000000; ... // Extract the contents of the <data> element
string tile_data = ... unsigned char *data = decompress(base64_decode(tile_data));
unsigned tile_index = 0; // Here you should check that the data has the right size
// (map_width * map_height * 4) for (int y = 0; y < map_height; ++y) {
for (int x = 0; x < map_width; ++x) {
unsigned global_tile_id = data[tile_index] |
data[tile_index + 1] << 8 |
data[tile_index + 2] << 16 |
data[tile_index + 3] << 24;
tile_index += 4; // Read out the flags
bool flipped_horizontally = (global_tile_id & FLIPPED_HORIZONTALLY_FLAG);
bool flipped_vertically = (global_tile_id & FLIPPED_VERTICALLY_FLAG);
bool flipped_diagonally = (global_tile_id & FLIPPED_DIAGONALLY_FLAG); // Clear the flags
global_tile_id &= ~(FLIPPED_HORIZONTALLY_FLAG |
FLIPPED_VERTICALLY_FLAG |
FLIPPED_DIAGONALLY_FLAG); // Resolve the tile
for (int i = tileset_count - 1; i >= 0; --i) {
Tileset *tileset = tilesets[i]; if (tileset->first_gid() <= global_tile_id) {
tiles[y][x] = tileset->tileAt(global_tile_id - tileset->first_gid());
break;
}
}
}
}

(Since the above code was put together on this wiki page and can't be directly tested, please make sure to report any errors you encounter when basing your parsing code on it, thanks.)

<tile>

  • gid: The global tile ID.

Not to be confused with the tile element inside a tileset, this element defines the value of a single tile on a tile layer. This is however the most inefficient way of storing the tile layer data, and should generally be avoided.

<objectgroup>

  • name: The name of the object group.
  • color: The color used to display the objects in this group.
  • x: The x coordinate of the object group in tiles. Defaults to 0 and can no longer be changed in Tiled Qt.
  • y: The y coordinate of the object group in tiles. Defaults to 0 and can no longer be changed in Tiled Qt.
  • width: The width of the object group in tiles. Meaningless.
  • height: The height of the object group in tiles. Meaningless.
  • opacity: The opacity of the layer as a value from 0 to 1. Defaults to 1.
  • visible: Whether the layer is shown (1) or hidden (0). Defaults to 1.

The object group is in fact a map layer, and is hence called "object layer" in Tiled Qt.

Can contain: properties, object

<object>

  • name: The name of the object. An arbitrary string.
  • type: The type of the object. An arbitrary string.
  • x: The x coordinate of the object in pixels.
  • y: The y coordinate of the object in pixels.
  • width: The width of the object in pixels (defaults to 0).
  • height: The height of the object in pixels (defaults to 0).
  • rotation: The rotation of the object in degrees clockwise (defaults to 0). (on git master)
  • gid: An reference to a tile (optional).
  • visible: Whether the object is shown (1) or hidden (0). Defaults to 1. (since 0.9.0)

While tile layers are very suitable for anything repetitive aligned to the tile grid, sometimes you want to annotate your map with other information, not necessarily aligned to the grid. Hence the objects have their coordinates and size in pixels, but you can still easily align that to the grid when you want to.

You generally use objects to add custom information to your tile map, such as spawn points, warps, exits, etc.

When the object has a gid set, then it is represented by the image of the tile with that global ID. Currently that means width and heightare ignored for such objects. The image alignment currently depends on the map orientation. In orthogonal orientation it's aligned to the bottom-left while in isometric it's aligned to the bottom-center.

Can contain: properties, ellipse (since 0.9.0), polygon, polyline, image

<ellipse/>

Used to mark an object as an ellipse. The regular x, y, width, height attributes are used to determine the size of the ellipse.

<polygon>

  • points: A list of x,y coordinates in pixels.

Each polygon object is made up of a space-delimited list of x,y coordinates. The origin for these coordinates is the location of the parent object. By default, the first point is created as 0,0 denoting that the point will originate exactly where the object is placed.

<polyline>

  • points: A list of x,y coordinates in pixels.

polyline follows the same placement definition as a polygon object.

<imagelayer>

  • name: The name of the image layer.
  • width: The width of the image layer in tiles. Meaningless.
  • height: The height of the image layer in tiles. Meaningless.
  • opacity: The opacity of the layer as a value from 0 to 1. Defaults to 1.
  • visible: Whether the layer is shown (1) or hidden (0). Defaults to 1.

A layer consisting of a single image.

Can contain: properties, image

<properties>

Can contain: property

Wraps any number of custom properties. Can be used as a child of the maptile (when part of a tileset), layerobjectgroup and object elements.

<property>

  • name: The name of the property.
  • value: The value of the property.

When the property spans contains newlines, the current versions of Tiled Java and Tiled Qt will write out the value as characters contained inside the property element rather than as the value attribute. However, it is at the moment not really possible to edit properties consisting of multiple lines with Tiled.

It is possible that a future version of the TMX format will switch to always saving property values inside the element rather than as an attribute.


Change Log

Below are described the changes/additions that were made to the TMX format for recent versions of Tiled.

Tiled git (master)

  • Tile objects can now be horizontally or vertically flipped. This is stored in the gid attribute using the same mechanism as for regular tiles. The image is expected to be flipped without affecting its position, same way as flipped tiles.

  • Objects can be rotated freely. The rotation is stored in degrees as a rotation attribute, with positive rotation going clockwise.

Tiled 0.9.0

  • Per-object visibility flag is saved (defaults to 1):
<object visible="0|1">
  • Terrain information was added to tileset definitions (this is generally not very relevant for games):
<tileset>
...
<terraintypes>
<terrain name="Name" tile="local_id"/>
</terraintypes>
<tile id="local_id" terrain="[n],[n],[n],[n]" probability="percentage"/>
...
</tileset>
  • There is preliminary support for a "staggered" (isometric) projection (new value for the orientation attribute of the map element).

  • A basic image layer type was added:

<imagelayer ...>
<image source="..."/>
</imagelayer>
  • Added ellipse object shape. Same parameters as rectangular objects, but marked as ellipse with a child element:
<object ...>
<ellipse/>
</object>
  • Added map property for specifying the background color:
<map ... backgroundcolor="#XXXXXX">
  • Added initial (non-GUI) support for individual and/or embedded tile images (since there is no way to set this up in Tiled Qt but only in Tiled Java or with pytmxlib, this is not very important to support at the moment):
<tileset ...>
<tile id="[n]">
<!-- an embedded image -->
<image format="png">
<data encoding="base64">
...
</data>
</image>
</tile>
<tile id="[n]">
<!-- an individually referenced image for a single tile -->
<image source="file.png"/>
</tile>
...
</tileset>

Tiled 0.8.0

  • Tilesets can now have custom properties (using the properties child element, just like everything else).

  • Tilesets now support defining a drawing offset in pixels, which is to be used when drawing any tiles from that tileset. Example:

<tileset name="perspective_walls" tilewidth="64" tileheight="64">
<tileoffset x="-32" y="0"/>
...
</tileset>
  • Support for tile rotation in 90-degree increments was added by using the third most significant bit in the global tile id. This new bit means "anti-diagonal flip", which swaps the x and y axis when rendering a tile.

tile xml格式的更多相关文章

  1. [转] IIS配置文件的XML格式不正确 applicationHost.config崩溃 恢复解决办法

    IIS配置文件的XML格式不正确 applicationHost.config崩溃 恢复解决办法 源文件:http://www.cnblogs.com/yuejin/p/3385584.html   ...

  2. 使用WCF传输DataTable:DataTable和Xml格式的字符串相互转换(C#)

    背景:项目中要用到客户端向服务端传数据,使用WCF,绑定webHttpBinding,做了一个小例子. 业务逻辑简介:客户端在a表中添加了几条数据,从SQL Server数据库直接取出新添加的数据(D ...

  3. Rss 订阅:php动态生成xml格式的rss文件

    Rss 简介: 简易信息聚合(也 叫聚合内容)是一种描述和同步网站内容的格式.使用RSS订阅能更快地获取信息,网站提供RSS输出,有利于让用户获取网站内容的最新更新.网络用户可以在客户端借助于支持RS ...

  4. C#RSA算法实现+如何将公钥为XML格式转为PEM格式,给object-C使用

    .net中,处于安全的考虑,RSACryptoServiceProvider类,解密时只有同时拥有公钥和私钥才可以.原因是公钥是公开的,会被多人持有.这样的数据传输是不安全的.C#RSA私钥加密,公钥 ...

  5. WP8解析XML格式文件

    DOTA2 WebAPI请求返回的格式有两种,一种是XML,一种是JSON,默认是返回JSON格式,如果要返回XML格式的话,需要在加上format=xml. 这里举一个简单的解析XML格式的例子(更 ...

  6. 怎么统计指定文件夹下含有.xml格式的文件数目

    如何统计指定文件夹下含有.xml格式的文件数目?如题 ------解决思路----------------------Directory.GetFiles(@"路径", " ...

  7. XPath注入跟SQL注入差不多,只不过这里的数据库走的xml格式

    SQL注入这块不想细聊了,相信很多朋友都听到耳朵长茧,不外乎是提交含有SQL操作语句的信息给后端,后端如果没有做好过滤就执行该语句,攻击者自然可以随意操纵该站点的数据库. 比如有一个图书馆站点book ...

  8. SQL 里解析 XML 格式 字段 信息

    DECLARE @ItemMessage XML ),zje ),yfje ),bcje ),URL ),Remark )) SET @ItemMessage=N'<List> <i ...

  9. Web APi入门之移除XML格式(一)

    前言 回头想来,没想到自己却坚持下来了,EntityFramework系列终于全部完成了,给自己点个赞先.本系列将着手于Web API,关于一些基础的介绍及定义就不再叙述,请参考园友们文章,非常详细, ...

随机推荐

  1. 2017多校第8场 HDU 6143 Killer Names 容斥,组合计数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6143 题意:m种颜色需要为两段长度为n的格子染色,且这两段之间不能出现相同的颜色,问总共有多少种情况. ...

  2. 构造函数、原型对象prototype、实例、隐式原型__proto__的理解

    (欢迎一起探讨,如果有什么地方写的不准确或是不正确也欢迎大家指出来~) PS: 内容中的__proto__可能会被markdown语法导致显示为proto. 建议将构造函数中的方法都定义到构造函数的原 ...

  3. Makefile系列之一 : 书写规则

    1. 规则 target : prerequisites command  2. example excute 为最终生成的可执行文件. 可以通过命令 make clean来删除所有编译时产生的中间文 ...

  4. JVM对象分配和GC分布【JVM】

    最近在学习java基础结构,刚好学到了jvm,总结了以下并可以结合思维导图认识以下Jvm的对象: 栈:什么是栈? 先说一下栈的数据结构吧,栈它是一种先进后出的数据结构(FILO),跟队列刚好相反(先进 ...

  5. windows下使用github

    1.首先到github.com注册用户: 2.下载git,地址:http://pan.baidu.com/s/1skPpWlB(64位下载):http://pan.baidu.com/s/1skOAa ...

  6. 用JavaScript校验日期的合法性

    校验表单时可能会遇到校验日期是否正确.可以利用JS的内置对象Date帮助我们完成日期校验. 思路是首先用被校验日期(假设为A,可能为字符串或数字)创建一个Date对象(假设为B). 然后判断A和B的年 ...

  7. redis之(十六)redis的cluster集群环境的搭建,转载

    最近redis已经比较火了,有关redis的详细介绍,网上有一大堆,我这里只作简单的介绍,然后跟大家一起学习Redis Cluster 3.0的搭建与使用.Redis是一款开源的.网络化的.基于内存的 ...

  8. redis之(二)redis单机的安装,配置,启动,关闭

    [1]下载redis压缩包,解压,编译

  9. OpenFalcon-SuitAgent

    http://www.cnblogs.com/qianlong2016/archive/2016/09/08/5853899.html

  10. Sql Server递归查询(转)

    有如下数据表 假如我们要查询ID为003的数据的所有子节点我们可以使用CTE 递归查询完成... if OBJECT_ID('tb','N') is not null drop table tb; c ...