LibGDX开发 - Tiled地图 之 图层

原文链接 http://doc.mapeditor.org/en/latest/manual/layers/

初稿2017-10-15,还待完善

术语对照:

  • Layer - 图层
  • Object - 对象

图层

Tiled地图支持多种内容(content),这些内容(content)放在在许多不同的图层中。最常见的图层是Tiled图层和对象图层。还有一个Image图层,用来将单一的前景/背景图片放入到地图中。图层的顺序决定了内容的渲染顺序。

图层可以设置为“不可见”,“部分可见”。图层也可以被“锁定”。图层也有“偏移”。(这句话不是很懂。。。 “位移”可以用来将不同图层之间进行定位,比如模拟深度。)

image

眼睛图标和锁图标显示了各图层的可见性和锁定状态。

可以用Group图层来组织各图层的层次关系。这样在存在大量图层的情况下非常有用。

Tile图层

Tile图层提供了一种用存储Tile数据的方法,TIle数据用来填充大面积区域。Tile数据是简单的数组,只包含了Tile的索引,因此每个位置不能存储额外的信息。仅有的额外信息是少量的标志位,这些标志位允许图形的垂直平铺,水平或者反对角翻转(用于支持90度增量旋转)。

渲染每个Tile层所需的信息与地图一起储存。该地图基于方向和其他属性来指定Tile的位置和渲染顺序。

尽管只能够引用tile,tile层也可用于定义您级别中的各种非图形信息。 通常可以使用特殊的tile set来传达碰撞信息,并且任何类型的不需要自定义属性并且始终与网格对齐的对象也可以被放置在瓦片层上。

Object Layer 对象层

Oject 层非常有用,因为对象可以存储很多中 Tile 层不能存储的信息。
Objects 可以自由摆放,缩放,旋转。他们可以有独立的自定义属性。
目前有很多Objects:

  • Rectangle - 用来定义矩形区域
  • Ellipse - 用来定义椭圆或者圆形区域
  • Polygon (多边形) - for when a rectangle or ellipse doesn’t cut it (often a collision area)
  • Polyline (折线) - 可以用来作为跟随的路性或者碰撞的墙。
  • Tile - 用来自由放置,缩放或者旋转你的Tile图形。
  • Text - 自定义文本或者注释(Tiled 1.0起开始支持)。

所有Objects都可以被命名。在这种情况下,他们的名字可以在他们上访的标签中显示(默认只有选中的Objects)。Objects可以被指定一种类型,这非常有用,因为可以给予类型去指定标签的颜色和可用的自定义属性。对于Tile Objects来说,类型可以从他们的Tile继承。

对于大多数地图类型来说,Objects是基于像素去定位的。唯一的例外是 Isometric地图(不是isometric staggered).对于isometri地图来说,他们的位置被存储在投影坐标中。如果你在等距游戏中为对象使用不同的坐标空间,则需要对应的转换这些坐标。

Object的宽和高也基本上基于像素储存。Isometric地图不懂。。。。

Image 层

Image层提供了一种在地图中包含单一前景/背景图片的快速方法。当前还作用不大,因为如果你将图片作为Tilesets加入,并放在Tile Objects, 你可以自由的缩放和旋转图片。

使用Image层的唯一优点是避免在使用“选择对象”工具时选择/拖动图像。 但是,从Tiled 1.1版本起,也可以通过锁定包含要避免交互的图块对象的对象层来实现。

Group Layers

Group 层类似于文件夹的形式,可以用来将各层组织起来。当地图中包含大量的图层时,这个功能较为有用。

Group层的可见性,透明图,偏移和锁定属性会应用于所有的子层。

可以使用鼠标将图层轻松地拖入group中。 提升层/下层动作还允许移动层进出组。

Layers can be easily dragged in and out of groups with the mouse. The Raise Layer / Lower Layer actions also allow moving layers in and out of groups.

未来的功能

层可以有更多强大的功能:

  • 能够锁定单个物体.
  • Moving certain map-global properties to the Tile Layer (#149). It would be useful if one map could accommodate layers of different tile sizes and maybe even of different orientation.

如果您喜欢任何这些计划,请通过成为顾客来帮助我更快地到达这个计划。 我得到的支持越多,我可以花更多的时间来改善Tiled!

英文原文如下,供参考

Working with Layers
A Tiled map supports various sorts of content, and this content is organized into various different layers. The most common layers are the Tile Layer and the Object Layer. There is also an Image Layer for including simple foreground or background graphics. The order of the layers determines the rendering order of your content.

Layers can be hidden, made only partially visible and can be locked. Layers also have an offset, which can be used to position them independently of each other, for example to fake depth.

Layers View
The eye and lock icon toggle the visibility and locked state of a layer respectively.

You use Group Layers to organize the layers into a hierarchy. This makes it more comfortable to work with a large amount of layers.

Tile Layers
Tile layers provide an efficient way of storing a large area filled with tile data. The data is a simple array of tile references and as such no additional information can be stored for each location. The only extra information stored are a few flags, that allow tile graphics to be flipped vertically, horizontally or anti-diagonally (to support rotation in 90-degree increments).

The information needed to render each tile layer is stored with the map, which specifies the position and rendering order of the tiles based on the orientation and various other properties.

Despite only being able to refer to tiles, tile layers can also be useful for defining various bits of non-graphical information in your level. Collision information can often be conveyed using a special tileset, and any kind of object that does not need custom properties and is always aligned to the grid can also be placed on a tile layer.

Object Layers
Object layers are useful because they can store many kinds of information that would not fit in a tile layer. Objects can be freely positioned, resized and rotated. They can also have individual custom properties. There are many kinds of objects:

Rectangle - for marking custom rectangular areas
Ellipse - for marking custom ellipse or circular areas
Polygon - for when a rectangle or ellipse doesn’t cut it (often a collision area)
Polyline - can be a path to follow or a wall to collide with
Tile - for freely placing, scaling and rotating your tile graphics
Text - for custom text or notes (since Tiled 1.0)
All objects can be named, in which case their name will show up in a label above them (by default only for selected objects). Objects can also be given a type, which is useful since it can be used to customize the color of their label and the available custom properties for this object type. For tile objects, the type can be inherited from their tile.

For most map types, objects are positioned in plain pixels. The only exception to this are isometric maps (not isometric staggered). For isometric maps, it was deemed useful to store their positions in a projected coordinate space. For this, the isometric tiles are assumed to represent projected squares with both sides equal to the tile height. If you’re using a different coordinate space for objects in your isometric game, you’ll need to convert these coordinates accordingly.

The object width and height is also mostly stored in pixels. For isometric maps, all shape objects (rectangle, ellipse, polygon and polyline) are projected into the same coordinate space described above. This is based on the assumption that these objects are generally used to mark areas on the map.

Image Layers
Image layers provide a way to quickly include a single image as foreground or background of your map. They are currently not so useful, because if you instead add the image as a Tileset and place it as a Tile Object, you gain the ability to freely scale and rotate the image.

The only advantage of using an image layer is that it avoids selecting / dragging the image while using the Select Objects tool. However, since Tiled 1.1 this can also be achieved by locking the object layer containing the tile object you’d like to avoid interacting with.

New in Tiled 1.0
Group Layers
Group layers work like folders and can be used for organizing the layers into a hierarchy. This is mainly useful when your map contains a large amount of layers.

The visibility, opacity, offset and lock of a group layer affects all child layers.

Layers can be easily dragged in and out of groups with the mouse. The Raise Layer / Lower Layer actions also allow moving layers in and out of groups.

Future Extensions

There are many ways in which the layers can be made more powerful:

Ability to lock individual objects (#828).
Moving certain map-global properties to the Tile Layer (#149). It would be useful if one map could accommodate layers of different tile sizes and maybe even of different orientation.
If you like any of these plans, please help me getting around to it faster by becoming a patron. The more support I receive the more time I can afford to spend improving Tiled!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,793评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,567评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,342评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,825评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,814评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,680评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,033评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,687评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,175评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,668评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,775评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,419评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,020评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,978评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,206评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,092评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,510评论 2 343

推荐阅读更多精彩内容