Jump to content

Tilemap issues


PMayhem
 Share

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');
    layer.resizeWorld(); 
}
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

Hey everyone, 

 

Thanks for the replies.

 

After a lot of trial and error, I updated to Phaser 2.2.1 which gave a few more hints in the dev console. Turns out Phaser can't handle more than 1 spritesheet. And I had 2 loaded in through my Tiled project. (Doh!)

Link to comment
Share on other sites

Can't handle more than one spritesheet? I'm fairly certain that there is no such limit. My project uses at least three spritesheet atlases and five different tilesets. Can you please show us what errors are logged when you try to load more than one spritesheet?

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

 Share

  • Recently Browsing   0 members

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