关于 class TileSet 中 tileProperties 的问题

Questions about tileProperties in class TileSet

我目前正在寻找将在 Tiled 中制作的瓦片地图导入相位器的方法。

在 Tiled 中,我创建了一个名为 "terrain" 的图块集,为图块集中的每个图块类型设置自定义属性,用一些图块类型填充地图,然后将地图导出为 json。

set tileProperties

然后在 Phaser 中,我将 json 作为 tilemap 加载到 Phaser 中。

//load the json into a tilemap
this.game.load.tilemap('plain', 'Content/map/plain.json', null, Phaser.Tilemap.TILED_JSON);
//initialize a new map from a loaded tile map
this.map = this.game.add.tilemap('plain');
//set the map tileset image
this.map.addTilesetImage('terrain', 'terrain');
//create the layer with the same name in the tilemap
this.layer = this.map.createLayer('background');

之后,我尝试访问加载的 tilemap 的 tileset "terrain" 的 tileProperties。

//get the tileindex of a tile at the coordinate (0,0)
var tileindex = this.map.getTile(0, 0, 'background').index;
//get the tileset index of the tileset that is named "terrain"
var tilesetindex = this.map.getTilesetIndex('terrain');
// get the tileset
var tileset = this.map.tilesets[tilesetindex];

但是后来,我发现 class TileSet 中没有 tileProperties。

所以我进入 github 存储库并搜索 "tileProperties",我发现在 TileMapParser.js 中有一块 code 设置了 tileProperties tileset 但 class TileSet 的定义中没有 tileProperties。

我的问题是为什么有设置 class TileSet 的 tileProperties 的代码,但 class TileSet 的定义中没有这样的 属性?

如果您尝试访问您在 Tiled 中设置的图块属性,您可以这样做:

// get a reference to the tile
var tile = this.map.getTile(0, 0, 'background');

// access the property
var property = tile.properties.property;

其中 属性 是您尝试访问的 属性 的名称,在您的情况下是地形。如果您不确定,可以在从 Tiled 导出的 json 中查找。

Phaser 网站上的

This example 很好地展示了这一点。

希望这对您有所帮助!