Jump to content

ObjectLayer from tiled throws, "Uncaught TypeError: Cannot read property 'length' of undefined "


SoulBeaver
 Share

Recommended Posts

As usual, I will begin with my tilemap:

 

AWYa9oC.png

 

As you can see I added three objects that I want to use in my map as triggers. This is the object layer called Triggers in tiled. I did not change my loading code because I assumed that you don't have to load the object layer:

        constructor(game: Phaser.Game, key: string, manifest: any) {            super(game, key);            this.addTilesets(manifest.maze);                        this.wallLayer       = this.createLayer(this.WallsLayer);            this.backgroundLayer = this.createLayer(this.BackgroundLayer);            this.shadowLayer     = this.createLayer(this.ShadowsLayer);            this.itemLayer       = this.createLayer(this.ItemsLayer);            this.objectLayer     = this.createLayer(this.ObjectsLayer);            this.creatureLayer   = this.createLayer(this.CreaturesLayer);            this.separateCreaturesFromTilemap();            this.separateItemsFromTilemap();            this.backgroundLayer.resizeWorld();            this.setCollisionBetween(1, 2, true, "Walls");        }

And this fails at runtime with the exception:

Uncaught TypeError: Cannot read property 'length' of undefined phaser.js:64576    Phaser.TilemapParser.parseTiledJSON phaser.js:64576    Phaser.TilemapParser.parse phaser.js:64260    Phaser.Tilemap phaser.js:61637    Tilemap Tilemap.ts:23    InGame.initializeMap     InGame.ts:36InGame.create     InGame.ts:26    Phaser.StateManager.loadComplete phaser.js:17993    Phaser.StateManager.preUpdate phaser.js:17753    Phaser.Game.update phaser.js:24518    Phaser.RequestAnimationFrame.updateRAF phaser.js:42978    _onLoop

Finally, here is the object layer as it is defined in the .json:

        {         "draworder":"topdown",         "height":8,         "name":"Triggers",         "objects":[                {                 "height":0,                 "name":"warp",                 "properties":                    {                     "map":"volcano"                    },                 "rotation":0,                 "type":"",                 "visible":true,                 "width":0,                 "x":60,                 "y":12                },                 {                 "height":0,                 "name":"warp",                 "properties":                    {                     "map":"desert"                    },                 "rotation":0,                 "type":"",                 "visible":true,                 "width":0,                 "x":276,                 "y":60                },                 {                 "height":0,                 "name":"spawn_player",                 "properties":                    {                    },                 "rotation":0,                 "type":"",                 "visible":true,                 "width":0,                 "x":60,                 "y":36                }],         "opacity":1,         "type":"objectgroup",         "visible":true,         "width":12,         "x":0,         "y":0        }
Link to comment
Share on other sites

if you want to use objects from the object layer you need to use 

map.createFromObjects

if you painted the objects with polylines (be aware that only the polylinetool works - not the polygon tool) then you need to use 

game.physics.p2.convertCollisionObjects(map,"Triggers");

this creates an array ob p2 bodies and you can cycle over them with a forloop and apply different configs to them..

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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