SoulBeaver

Unable to load Tiled .json file "Uncaught TypeError: Cannot read property '2' of undefined "

Recommended Posts

Hello,

 

 

I've recently acquired some sprites from Oryx and have attempted to load the sample Tiled file contained within. I'm able to load the assets just fine in my Preloader:

 

        loadAssets() {
            this.load.tilemap("oryx_tilemap", "assets/tilemaps/maps/oryx_test.json", null, Phaser.Tilemap.TILED_JSON);
 
            this.load.image("oryx_creatures", "assets/tilemaps/tiles/oryx_creatures.png");
            this.load.image("oryx_items", "assets/tilemaps/tiles/oryx_items.png");
            this.load.image("oryx_tiles", "assets/tilemaps/tiles/oryx_tiles.png");
            this.load.image("oryx_world", "assets/tilemaps/tiles/oryx_world.png");
            this.load.image("oryx_world2", "assets/tilemaps/tiles/oryx_world2.png");
        }
 
However, as soon as I attempt to "do" anything with the map, it crashes:
 
        create() {
            this.game.stage.backgroundColor = "#ffffff";
 
            this.map = this.game.add.tilemap("oryx_tilemap"); // Error here
            this.map.addTilesetImage("oryx_world", "oryx_world");
            this.map.addTilesetImage("oryx_creatures", "oryx_creatures");
            this.map.addTilesetImage("oryx_items", "oryx_items");
            this.map.addTilesetImage("oryx_world2", "oryx_world2");
 
            this.layer = this.map.createLayer("background");
            this.layer.resizeWorld();
        }
 
With the following error message:
 
Uncaught TypeError: Cannot read property '2' of undefined
Phaser.TilemapParser.parseTiledJSON 
Phaser.TilemapParser.parse
Phaser.Tilemap
Phaser.GameObjectFactory.tilemap
InGame.create
Phaser.StateManager.loadComplete
Phaser.StateManager.preUpdate
Phaser.Game.update
Phaser.RequestAnimationFrame.updateRAF
 
 
I'm not aware that I'm messing something up, judging from the tilemap example. What could I be doing wrong? Is the tilemap using any properties that are unsupported by Phaser?

Share this post


Link to post
Share on other sites

Hello lastnightsparty,

 

 

thank you for your input! It steered me in the right direction. First, Tiled does not export the transparent background color. If your tiles have a black background, Tiled will respect that in the editor but not export it. Phaser will then pick up the tiles and render them with a black background.

 

Secondly, and this is largely my mistake, I used the wrong tileset image. Oops :(

 

Thanks for the help!

Share this post


Link to post
Share on other sites

@lastnightsparty 

Thank you so much...

I am having trouble with this the whole day.

Literally spended more than 5 hours cheking my JSON file for anything.

On 11/4/2014 at 5:16 PM, lastnightsparty said:

Hi SoulBeaver,

 

I encountered this error also a few weeks ago.

 

The simple fix for me was to make sure that no tiles in Tiled used 'rotation'. Phaser doesn't seem to recognize rotation in Tiled. It's best to create a new rotated file and add it to the tile set.

Saved my party later :)

Share this post


Link to post
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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.