我正在使用Meteor.js服務器上的Paser.js。Phaser.js:無法讀取平鋪地圖圖層上的屬性'0'
它工作得很好,直到我嘗試使用平鋪地圖here。
這裏是我的代碼:
JS:
if (Meteor.isClient) {
Template.Game.onCreated(function()
{
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {
preload: preload,
create: create,
update: update
});
var map;
var backgroundLayer;
var blockLayer;
var bg;
function preload()
{
// load all game assets
// images, spritesheets, atlases, audio etc..
game.load.tilemap('myTilemap', 'assets/tilemaps/scifi.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('myTileset', "assets/tilemaps/scifi_platformTiles_32x32.png");
}
function create()
{
map = game.add.tilemap('myTilemap');
map.addTilesetImage('scifi_platformTiles_32x32', 'myTileset');
backgroundLayer = map.createLayer('background');
blockLayer = map.createLayer('blocklayer');
}
function update()
{
}
});
}
HTML:
<head>
<meta charset="UTF-8" />
<title>Phaser - Making your first game, part 1</title>
<script type="text/javascript" src="phaser.min.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<h1>Welcome to my first Phaser game!</h1>
{{> Game}}
</body>
<template name="Game">
<div id="phaserCanvas"></div>
</template>
而且,當我嘗試在localhost:3000,我得到:
Uncaught TypeError: Cannot read property '0' of undefined
來自phaser.min.js:15。這產生警告的線
blockLayer = map.createLayer('blocklayer');
看來,移相器可以正確讀取從scifi.json的'background'
層信息,但不是'blocklayer'
之一。
下面是來自scifi.json的摘錄:
{ "height":20,
"layers":[
{
"compression":"zlib",
"data": "[Some very long hashed key...]",
"encoding":"base64",
"height":20,
"name":"background",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":20,
"x":0,
"y":0
},
{
"compression":"zlib",
"data":"[Some very long hashed key...]",
"encoding":"base64",
"height":20,
"name":"blocklayer",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":20,
"x":0,
"y":0
}],
"nextobjectid":1,
[...]
而且我還是老樣子無法找出什麼問題?有沒有人遇到了嗎?
更多信息:
我用原子作爲IDE
我試着與移相器V2.0.1和移相器V2.4.2
謝謝你。
要修復錯誤,請在Tiled中轉到Map - > Map properties - > Tile Layer Format並選擇CSV。然後導出新的.json文件。 – Sawny