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>Welcome 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":[
{
"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,
[...]
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.
Seems the problem came from Tiled : the hashed key was compressed with Zlib, though it should not be compressed 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 (uncompressed) and it should work :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With