SoulBeaver Posted November 29, 2014 Share Posted November 29, 2014 As usual, I will begin with my tilemap: 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 _onLoopFinally, 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 More sharing options...
valueerror Posted November 30, 2014 Share Posted November 30, 2014 if you want to use objects from the object layer you need to use map.createFromObjectsif 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 More sharing options...
Recommended Posts