tile xml格式
<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 firstgid
s.
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 height
are 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.
A 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 map
, tile
(when part of a tileset
), layer
, objectgroup
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 themap
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格式的更多相关文章
- [转] IIS配置文件的XML格式不正确 applicationHost.config崩溃 恢复解决办法
IIS配置文件的XML格式不正确 applicationHost.config崩溃 恢复解决办法 源文件:http://www.cnblogs.com/yuejin/p/3385584.html ...
- 使用WCF传输DataTable:DataTable和Xml格式的字符串相互转换(C#)
背景:项目中要用到客户端向服务端传数据,使用WCF,绑定webHttpBinding,做了一个小例子. 业务逻辑简介:客户端在a表中添加了几条数据,从SQL Server数据库直接取出新添加的数据(D ...
- Rss 订阅:php动态生成xml格式的rss文件
Rss 简介: 简易信息聚合(也 叫聚合内容)是一种描述和同步网站内容的格式.使用RSS订阅能更快地获取信息,网站提供RSS输出,有利于让用户获取网站内容的最新更新.网络用户可以在客户端借助于支持RS ...
- C#RSA算法实现+如何将公钥为XML格式转为PEM格式,给object-C使用
.net中,处于安全的考虑,RSACryptoServiceProvider类,解密时只有同时拥有公钥和私钥才可以.原因是公钥是公开的,会被多人持有.这样的数据传输是不安全的.C#RSA私钥加密,公钥 ...
- WP8解析XML格式文件
DOTA2 WebAPI请求返回的格式有两种,一种是XML,一种是JSON,默认是返回JSON格式,如果要返回XML格式的话,需要在加上format=xml. 这里举一个简单的解析XML格式的例子(更 ...
- 怎么统计指定文件夹下含有.xml格式的文件数目
如何统计指定文件夹下含有.xml格式的文件数目?如题 ------解决思路----------------------Directory.GetFiles(@"路径", " ...
- XPath注入跟SQL注入差不多,只不过这里的数据库走的xml格式
SQL注入这块不想细聊了,相信很多朋友都听到耳朵长茧,不外乎是提交含有SQL操作语句的信息给后端,后端如果没有做好过滤就执行该语句,攻击者自然可以随意操纵该站点的数据库. 比如有一个图书馆站点book ...
- SQL 里解析 XML 格式 字段 信息
DECLARE @ItemMessage XML ),zje ),yfje ),bcje ),URL ),Remark )) SET @ItemMessage=N'<List> <i ...
- Web APi入门之移除XML格式(一)
前言 回头想来,没想到自己却坚持下来了,EntityFramework系列终于全部完成了,给自己点个赞先.本系列将着手于Web API,关于一些基础的介绍及定义就不再叙述,请参考园友们文章,非常详细, ...
随机推荐
- golang相关问题
[转载][翻译]Go的50坑:新Golang开发者要注意的陷阱.技巧和常见错误[1] Golang作为一个略古怪而新的语言,有自己一套特色和哲学.从其他语言转来的开发者在刚接触到的时候往往 ...
- iframe弹出框js ie6下存在bug
ie6的iframe在第一次加载的显示不出来,显示空白,但是很奇怪,刷新就可以正常显示了,一开始以为这只是IE6下iframe加载的bug,但是最后结果发现这是ie6下javascript延迟加载出现 ...
- [USACO06NOV]路障---严格次短路
Description 贝茜把家搬到了一个小农场,但她常常回到FJ的农场去拜访她的朋友.贝茜很喜欢路边的风景,不想那么快地结束她的旅途,于是她每次回农场,都会选择第二短的路径,而不象我们所习惯的那样, ...
- JQuery 实现 锚点跳转
$('.nav-jump').click(function() { $('html,body').animate( { scrollTop:$($.attr(this, 'href')).offset ...
- 微信小程序-表格形式如何布局?
微信小程序没有现成的table标签,该怎么布局呢? <view class="my-grids"> <block wx:for="{{grids}}&q ...
- spring-web涉及jar包说明
<!-- spring-context, spring-aop, spring-beans, spring-core, spring-expression --> <dependen ...
- AC日记——Dynamic Ranking 洛谷 P2617
Dynamic Ranking 思路: 可持久化树状数组: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1 ...
- Visual Studio Code 相关设置
Visual Studio Code 编译 SASS 到 CSS : 1.安装node 环境 2.Ctrl + Shift + ~,打开终端窗口 cd 到 SASS 文件目录,node-sass Te ...
- C#读取RSS源,并利用Solr索引
折磨我几天的问题今天终于解决了,分享一下近期solr使用的一些经验. 本来是用nutch在爬取页面,可是客户需要爬取RSS,而且可以识别那些页面是通过RSS源抓取出来的.nutch虽然自带解析RSS的 ...
- 前端读者 | 如何判断Javascript对象是否存在
本文来自@阮一峰 Javascript语言的设计不够严谨,很多地方一不小心就会出错. 举例来说,请考虑以下情况. 现在,我们要判断一个全局对象myObj是否存在,如果不存在,就对它进行声明.用自然语言 ...