admin管理员组文章数量:1323323
I'm working with Paser.js on a Meteor.js server.
It worked wperfectly until I try to use tiled maps as described here.
Here is my code :
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>Wele to my first Phaser game!</h1>
{{> Game}}
</body>
<template name="Game">
<div id="phaserCanvas"></div>
</template>
And, when I try it on localhost:3000, I get :
Uncaught TypeError: Cannot read property '0' of undefined
From phaser.min.js:15. The line which generate that warning is
blockLayer = map.createLayer('blocklayer');
It seems that phaser can correctly read the 'background'
layer information from the scifi.json, but not the 'blocklayer'
one.
Here is an extract from the scifi.json :
{ "height":20,
"layers":[
{
"pression":"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
},
{
"pression":"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,
[...]
And I'm stil unable to find out what's the problem... Has anyone faced that before ?
More informations :
I use Atom as IDE
I tried with Phaser v2.0.1 and Phaser v2.4.2
Thanks you.
I'm working with Paser.js on a Meteor.js server.
It worked wperfectly until I try to use tiled maps as described here.
Here is my code :
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>Wele to my first Phaser game!</h1>
{{> Game}}
</body>
<template name="Game">
<div id="phaserCanvas"></div>
</template>
And, when I try it on localhost:3000, I get :
Uncaught TypeError: Cannot read property '0' of undefined
From phaser.min.js:15. The line which generate that warning is
blockLayer = map.createLayer('blocklayer');
It seems that phaser can correctly read the 'background'
layer information from the scifi.json, but not the 'blocklayer'
one.
Here is an extract from the scifi.json :
{ "height":20,
"layers":[
{
"pression":"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
},
{
"pression":"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,
[...]
And I'm stil unable to find out what's the problem... Has anyone faced that before ?
More informations :
I use Atom as IDE
I tried with Phaser v2.0.1 and Phaser v2.4.2
Thanks you.
Share edited Aug 16, 2015 at 16:02 David Panart asked Aug 16, 2015 at 15:45 David PanartDavid Panart 6566 silver badges21 bronze badges2 Answers
Reset to default 8Seems the problem came from Tiled : the hashed key was pressed with Zlib, though it should not be pressed at all as phaser do not support it yet.
In tiled, go to Map -> Map Properties There you will find Tile Layer Format. Change this to Base64 (unpressed) and it should work :)
本文标签: javascriptPhaserjscannot read property 39039 on tiled map layerStack Overflow
版权声明:本文标题:javascript - Phaser.js : cannot read property '0' on tiled map layer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742142254a2422632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论