我遇到以下错误:
无法读取未定义的属性“ width” 在新的Phaser中。瓷砖图
我的脚本:
var game = new Phaser.Game(1024, 640, Phaser.AUTO, 'auto-def', { preload: preload, create: create, update: update });
let map;
function preload () {
game.load.tilemap('td-map-1", "./assets/auto-def-1.json',null, Phaser.Tilemap.TILED_JSON);
game.load.image('tiles','./assets/tilesheet.png');
}
function create () {
map = game.add.tilemap('td-map-1');
map.addTilesetImage('tilesheet', 'tiles');
layer = map.createLayer('yer');
layer.resizeWorld();
}
function update () {
}
上面引用的“ auto-def-1.json”文件的内容:
{ "height":5,
"infinite":false,
"layers":[
{
"data":[25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25],
"height":5,
"id":1,
"name":"yer",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":8,
"x":0,
"y":0
},
{
"data":[0, 258, 0, 0, 0, 0, 0, 0, 0, 258, 0, 258, 258, 258, 0, 0, 0, 258, 0, 258, 0, 258, 0, 0, 0, 258, 258, 258, 0, 258, 0, 0, 0, 0, 0, 0, 0, 258, 0, 0],
"height":5,
"id":2,
"name":"yol",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":8,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 250, 0, 0, 0, 0, 0, 0, 0, 251, 0, 0, 0, 0, 0, 0, 0, 207, 0, 0, 0, 0, 0, 0, 0, 206, 0, 0, 0, 0, 0, 0, 0, 205],
"height":5,
"id":3,
"name":"kule",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":8,
"x":0,
"y":0
}],
"nextlayerid":4,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.2.4",
"tileheight":128,
"tilesets":[
{
"firstgid":1,
"source":"D:\/Projects\/auto-defense\/towerDefense_tilesheet@2.tsx"
}],
"tilewidth":128,
"type":"map",
"version":1.2,
"width":8
}