Jump to content

Tilemap issues


Recommended Posts

Hi All,


New to phaser as I wanted to try my hand at game dev.

I write business apps with ASP.NET Ajax so the odd bit of javascript doesn't scare me.


Anyhow, I've been struggling for an entire evening trying to load a Tiled generated tilemap.

json file is all present and correct and I've tried a variety off different tutorials/examples but al I get in the dev console is:

'Uncaught TypeError: Cannot read property '2' of undefined'


Here's what I'm trying to use


var game = new Phaser.Game(800, 600, Phaser.AUTO, 'mapPhaser', { preload: preload, create: create, update: update });
function preload() {
//Load the spritesheet for the tilemap
    game.load.image('tileset', 'assets/sheet.png');
//Load the tilemap file
    game.load.tilemap('map', 'assets/tilemaps/level1.json', null, Phaser.Tilemap.TILED_JSON);
var map;
var layer;
function create() {
    map = this.add.tilemap('map');
    map.addTilesetImage('tiles_spritesheet', 'tileset');
    layer = map.createLayer('backgroundLayer');
function update() {


Link to comment
Share on other sites

I got the same error which looks like it was down to Phaser's parsing of the JSON not being robust enough and/or Tiled incorrectly formatting it.  I say the latter because the tilemap loaded and worked, then I added a collision ellipse to a tile which broke it.  Removing the collision ellipse only partially returned the JSON to its former state, removing the details of the collision ellipse, but leaving the section in the TMX project file and exported JSON.  I mention Phaser because it reports incorrectly that "Phaser.TilemapParser - Image Collection Tilesets are not support(ed)".


So it smells like you have incompatible information in your Tiled file.  For me, removing the empty <tile id... /tile> section in the Tiled TMX sorted it out (which translates to the "tiles" object in "tileset" in the JSON.)

Link to comment
Share on other sites

Yes, that's not the issue.  The issue is that parseTiledJSON in TilemapParser throws an error when there is a "tiles" node present in a description of a "tilemaps" object.  Whilst the error message is that Phaser doesn't support Image Collections, Tiled also uses this to store tile specific info when a spritesheet is the image source.

Link to comment
Share on other sites

Not sure about the tiles node in the Json file as I've now overwritten it with a working one. I'll see if I can re-create the error and post the message.


I may have inadvertently jumped the gun on blaming Phaser for the problem! Let me grab the error message again to confirm..


In the meantime, I'm now struggling with getting a background layer to repeat with:

game.add.tileSprite(0, 0, 1024,1024, 'sky'); 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...