有关TileSet类

时间:2017-06-18 09:38:59

标签: javascript typescript phaser-framework

我目前正在寻找将Tiled制作的瓷砖地图导入移相器的方法。

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

set tileProperties

然后在移相器中,我将json加载到移相器中作为tilemap。

//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];

然而,我发现TileSet类中没有tileProperties。

所以我进入github存储库并搜索“tileProperties”,我发现TileMapParser.js中有一段code为tileset设置了tileProperties,但TileSet类的定义中没有tileProperties

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

1 个答案:

答案 0 :(得分:0)

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

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

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

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

移相网站上的

This example非常好地证明了这一点。

希望这有帮助!