Javascript 平铺中的平铺ID来自哪里?

Javascript 平铺中的平铺ID来自哪里?,javascript,php,phaser-framework,tiled,Javascript,Php,Phaser Framework,Tiled,过去我曾为游戏构建JSON tilemap文件。我现在想用PHP动态构建我的应用程序 下面是一个示例对象: { "height": 50, "layers": [{ "data": [5884, 5885, 5886, 5887, 5888, 5885], "height": 50, "name": "background", "opacity": 1, "type": "tilelayer",

过去我曾为游戏构建JSON tilemap文件。我现在想用PHP动态构建我的应用程序

下面是一个示例对象:

{
    "height": 50,
    "layers": [{
        "data": [5884, 5885, 5886, 5887, 5888, 5885],
        "height": 50,
        "name": "background",
        "opacity": 1,
        "type": "tilelayer",
        "visible": true,
        "width": 50,
        "x": 0,
        "y": 0
    }],
    "orientation": "orthogonal",
    "properties": {},
    "tileheight": 16,
    "tilesets": [{
        "firstgid": 1,
        "image": "tiles.png",
        "imageheight": 1684,
        "imagewidth": 2738,
        "margin": 1,
        "name": "tiles",
        "properties": {},
        "spacing": 1,
        "tileheight": 16,
        "tilewidth": 16
    }],
    "tilewidth": 16,
    "version": 1,
    "width": 50
}
这些属性是非常自解释的,并在上进行了记录,其中引用了平铺网站上的,但两个属性都没有解释层的
数据
属性的平铺id是如何生成的

两个问题:

1) 如何为“数据”数组生成磁贴ID?例如,如果我有一张5x5的瓷砖,它们会从左到右,从上到下是1到25吗


2) 数据数组使用全局ID,这些ID在所有平铺工作表中都是唯一的。这些是如何产生的?例如,如果我有3个5x5瓷砖板,它们会是1-75吗?但顺序是什么?

基于测试,我将根据平铺0.16.1的行为,以相反的顺序回答您的问题

您可能还希望最初添加单个图像,并使用XML输出(*.tmx),因为在我看来,查看数据格式要比JSON输出容易一些。我在下面提供一个:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="64" tileheight="64" nextobjectid="1">
 <tileset firstgid="1" name="second" tilewidth="64" tileheight="64" tilecount="3" columns="0">
  <tile id="0">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/forest.png"/>
  </tile>
  <tile id="1">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/forest-dirt-corner-ne.png"/>
  </tile>
  <tile id="2">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/forest-dirt-corner-nw.png"/>
  </tile>
 </tileset>
 <tileset firstgid="4" name="third" tilewidth="64" tileheight="64" tilecount="1" columns="0">
  <tile id="0">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/grass.png"/>
  </tile>
 </tileset>
 <tileset firstgid="5" name="first" tilewidth="64" tileheight="64" tilecount="2" columns="0">
  <tile id="0">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/dirt.png"/>
  </tile>
  <tile id="1">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/dirt-forest-corner-ne.png"/>
  </tile>
 </tileset>
 <layer name="Tile Layer 1" width="10" height="10">
  <data encoding="csv">
1,2,3,0,0,0,0,0,0,0,
4,0,0,0,0,0,0,0,0,0,
5,6,0,0,0,0,0,0,0,0,
1,2,3,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
</data>
 </layer>
</map>

1,2,3,0,0,0,0,0,0,0,
4,0,0,0,0,0,0,0,0,0,
5,6,0,0,0,0,0,0,0,0,
1,2,3,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
2。如何生成ID?

首先,必须了解有一个或多个
tileset
元素具有
firstgid
属性:

firstgid:此瓷砖集的第一个全局瓷砖ID(此全局ID映射到此瓷砖集中的第一个瓷砖)

此外:

第一个
tileset
始终具有
firstgid
值1

再进一步,我们将对
平铺
标识
进行解释:

id:其平铺集中的本地平铺id

因此,在上面的示例中,您将看到
tileset firstgid=“1”
中包含三个
tile
元素,其中
id
s的范围为0到2。进行数学运算时,您会看到这些是具有唯一ID 1、2和3的平铺

下一个
tileset
firstgid
为4,因为具有
id
s1、2和3的tile已经出现在前面。其中第一个
tile
id
为0,由于4+0=4,我们知道第四个
tile
是什么

如果在平铺界面中移动平铺集,则ID也会相应更新。因此,第一个瓷砖集中的第一个瓷砖的id始终为1

例如,如果我有3个5x5瓷砖板,它们会是1-75吗?但顺序是什么

是的,这将基于添加瓷砖板的瓷砖组的顺序

1。如何为
数据
数组生成ID?

ID基于生成的ID,这与上面回答的第二个问题有关。”“0”表示没有磁贴,而“1”将是第一个磁贴集中的第一个磁贴(左上角)

因此:

例如,如果我有一张5x5的瓷砖,它们会从左到右,从上到下是1到25吗


是的。

基于测试,我将根据平铺0.16.1的行为,以相反的顺序回答您的问题

您可能还希望最初添加单个图像,并使用XML输出(*.tmx),因为在我看来,查看数据格式要比JSON输出容易一些。我在下面提供一个:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="64" tileheight="64" nextobjectid="1">
 <tileset firstgid="1" name="second" tilewidth="64" tileheight="64" tilecount="3" columns="0">
  <tile id="0">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/forest.png"/>
  </tile>
  <tile id="1">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/forest-dirt-corner-ne.png"/>
  </tile>
  <tile id="2">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/forest-dirt-corner-nw.png"/>
  </tile>
 </tileset>
 <tileset firstgid="4" name="third" tilewidth="64" tileheight="64" tilecount="1" columns="0">
  <tile id="0">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/grass.png"/>
  </tile>
 </tileset>
 <tileset firstgid="5" name="first" tilewidth="64" tileheight="64" tilecount="2" columns="0">
  <tile id="0">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/dirt.png"/>
  </tile>
  <tile id="1">
   <image width="64" height="64" source="../../../OneDrive/Projects/Tiles/dirt-forest-corner-ne.png"/>
  </tile>
 </tileset>
 <layer name="Tile Layer 1" width="10" height="10">
  <data encoding="csv">
1,2,3,0,0,0,0,0,0,0,
4,0,0,0,0,0,0,0,0,0,
5,6,0,0,0,0,0,0,0,0,
1,2,3,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
</data>
 </layer>
</map>

1,2,3,0,0,0,0,0,0,0,
4,0,0,0,0,0,0,0,0,0,
5,6,0,0,0,0,0,0,0,0,
1,2,3,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0
2。如何生成ID?

首先,必须了解有一个或多个
tileset
元素具有
firstgid
属性:

firstgid:此瓷砖集的第一个全局瓷砖ID(此全局ID映射到此瓷砖集中的第一个瓷砖)

此外:

第一个
tileset
始终具有
firstgid
值1

再进一步,我们将对
平铺
标识
进行解释:

id:其平铺集中的本地平铺id

因此,在上面的示例中,您将看到
tileset firstgid=“1”
中包含三个
tile
元素,其中
id
s的范围为0到2。进行数学运算时,您会看到这些是具有唯一ID 1、2和3的平铺

下一个
tileset
firstgid
为4,因为具有
id
s1、2和3的tile已经出现在前面。其中第一个
tile
id
为0,由于4+0=4,我们知道第四个
tile
是什么

如果在平铺界面中移动平铺集,则ID也会相应更新。因此,第一个瓷砖集中的第一个瓷砖的id始终为1

例如,如果我有3个5x5瓷砖板,它们会是1-75吗?但顺序是什么

是的,这将基于添加瓷砖板的瓷砖组的顺序

1。如何为
数据
数组生成ID?

ID基于生成的ID,这与上面回答的第二个问题有关。”“0”表示没有磁贴,而“1”将是第一个磁贴集中的第一个磁贴(左上角)

因此:

例如,如果我有一张5x5的瓷砖,它们会从左到右,从上到下是1到25吗