【发布时间】:2017-06-20 06:22:18
【问题描述】:
我目前正在寻找将 Tiled 制作的瓦片地图导入移相器的方法。
在 Tiled 中,我创建了一个名为“terrain”的瓦片集,为瓦片集中的每个瓦片类型设置自定义属性,用一些瓦片类型填充地图,然后将地图导出为 json。
然后在移相器中,我将所述 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 的定义中却没有这样的属性?
【问题讨论】:
标签: javascript typescript phaser-framework