Jump to content

Cant load tiled map with phaser.


tarnos12
 Share

Recommended Posts

Hello, I am trying to load a tiled map with phaser, I get an error when adding layer:

 

Uncaught TypeError: Cannot read property '0' of undefined

Phaser.TilemapLayer.renderRegion @ phaser.js:92165 Phaser.TilemapLayer.renderFull @ phaser.js:92328 Phaser.TilemapLayer.render @ phaser.js:92403 Phaser.TilemapLayer.postUpdate @ phaser.js:91634 Phaser.Group.postUpdate @ phaser.js:32511 Phaser.Stage.postUpdate @ phaser.js:30883 Phaser.Game.updateLogic @ phaser.js:34688 Phaser.Game.update @ phaser.js:34619 Phaser.RequestAnimationFrame.updateRAF @ phaser.js:58258

_onLoop

 

and the error stops at: 

 var tile = row[x];

It cannot read row[0]; I guess, is there any tutorial step by step how to load it?

Also before this error I get 2 messages in console: 

Phaser.Tileset - image tile area is not an even multiple of tile sizephaser.js:93527 Phaser.Tileset - image tile area is not an even multiple of tile size

I am loading a tiled map like this: 

 

Preload:

game.load.tilemap('testmap', 'assets/data/untitled.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('url', 'assets/images/url.png');

Create:

this.mymap = game.add.tilemap('testmap');this.mymap.addTilesetImage('url');        this.layermain = this.mymap.createLayer('Tiles');this.layerBackground = this.mymap.createLayer('Background');this.layerBackground.resizeWorld();

My tiled file has 4 layers, Background,Tiles,player,enemy, tileset image name is "url". 

 

Json file created with tiled: 

{ "height":12, "layers":[        {         "compression":"zlib",         "data":"eJzt07kNwkAUBuG1xH0VATZ3\/yVxY1MCE9CAJSTe4gm+YKUJ\/uBtnVKqJUmSJEmSJEnZueOB5+fd4IUTzrjgilvGbZQdXWmj72vTjouUJphihjkW6KGPAYYYFfm2UXZ0pY2+r027wRY77HHAEUusUKLCOuM2yo6utNH3tWmb9B+qQvq+X9+1\/0ORvQEfiX6t",         "encoding":"base64",         "height":12,         "name":"Background",         "opacity":1,         "type":"tilelayer",         "visible":true,         "width":200,         "x":0,         "y":0        },         {         "compression":"zlib",         "data":"eJzt1sEJgDAMQNG6tzencAp1IHcRwVMhjdCDVN6DD0ouHhKwFAAAgPEsX38AAMCA6n+o+\/18qp\/fOqa+OYyuteN7sv\/R3N3wF60b2JI9j+bZXUGvWVLYKinsAiqA5Vg=",         "encoding":"base64",         "height":12,         "name":"Tiles",         "opacity":1,         "type":"tilelayer",         "visible":true,         "width":200,         "x":0,         "y":0        },         {         "draworder":"topdown",         "height":0,         "name":"enemy",         "objects":[                {                 "gid":374,                 "height":21,                 "id":15,                 "name":"",                 "properties":                    {                    },                 "rotation":0,                 "type":"",                 "visible":true,                 "width":21,                 "x":315.333333333333,                 "y":209.833333333333                }],         "opacity":1,         "type":"objectgroup",         "visible":true,         "width":0,         "x":0,         "y":0        },         {         "draworder":"topdown",         "height":10,         "name":"player",         "objects":[                {                 "gid":20,                 "height":21,                 "id":12,                 "name":"",                 "properties":                    {                    },                 "rotation":0,                 "type":"",                 "visible":true,                 "width":21,                 "x":63.25,                 "y":210.204545454545                }],         "opacity":1,         "type":"objectgroup",         "visible":true,         "width":50,         "x":0,         "y":0        }], "nextobjectid":16, "orientation":"orthogonal", "properties":    {    }, "renderorder":"right-down", "tileheight":21, "tilesets":[        {         "firstgid":1,         "image":"url.png",         "imageheight":367,         "imagewidth":689,         "margin":0,         "name":"url",         "properties":            {            },         "spacing":2,         "tilecount":480,         "tileheight":21,         "tilewidth":21,         "transparentcolor":"#5e81a2"        }], "tilewidth":21, "version":1, "width":200}

I hope this much information is enough. Let me know if you need more info. 

Also note that I have webconfig created, since I had troubles with loading json files before too, I found a solution on the forums tho. :)

Link to comment
Share on other sites

Hey, thanks for the answer, I started over and I have another error: 

 

Tilemap.createLayer: Invalid layer ID given: null 

 

My json code: 

{ "height":15, "layers":[        {         "data":"7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAAD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AAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA7gAAAO4AAADuAAAA",         "encoding":"base64",         "height":15,         "name":"Background",         "opacity":1,         "type":"tilelayer",         "visible":true,         "width":30,         "x":0,         "y":0        },         {         "data":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAAIQAAACEAAAAhAAAA",         "encoding":"base64",         "height":15,         "name":"Ground",         "opacity":1,         "type":"tilelayer",         "visible":true,         "width":30,         "x":0,         "y":0        },         {         "data":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAIYAAADCAAAAwgAAAIYAAADCAAAAwgAAAIYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",         "encoding":"base64",         "height":15,         "name":"Ledges",         "opacity":1,         "type":"tilelayer",         "visible":true,         "width":30,         "x":0,         "y":0        }], "nextobjectid":1, "orientation":"orthogonal", "properties":    {    }, "renderorder":"right-down", "tileheight":21, "tilesets":[        {         "firstgid":1,         "image":"url.png",         "imageheight":372,         "imagewidth":694,         "margin":3,         "name":"url",         "properties":            {            },         "spacing":2,         "tilecount":480,         "tileheight":21,         "tilewidth":21,         "transparentcolor":"#5e81a2"        }], "tilewidth":21, "version":1, "width":30}
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.

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

  • Recently Browsing   0 members

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