Phaser.js: unable to read property β€œ0” on broken map layer

I work with Paser.js on the Meteor.js server.

This worked inefficiently until I tried using tiled cards, 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' from undefined

From phaser.min.js: 15. The line that generates this warning is

blockLayer = map.createLayer('blocklayer');

It seems that the phaser can correctly read layer information 'background'from scifi.json, but not 'blocklayer'.

Here is an excerpt from 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 can’t understand what the problem is ... Has anyone encountered this before?

Additional Information:

  • I use Atom as an IDE

  • I tried with Phaser v2.0.1 and Phaser v2.4.2

Thanks.

+4
2

, Tiled: Zlib, , phaser .

+8

β†’ Tile Layer Format. Base64 (), :)

+3

All Articles