Pau Posted March 25, 2018 Share Posted March 25, 2018 Hello, I am trying to load a tilemap json file made with the tiled program. I am looking for phaser 3 equivalent to this phaser 2 code: function preload(){ this.load.image('gameTiles', 'tiles_spritesheet.png'); this.load.tilemap('level1', 'map.json', null, Phaser.Tilemap.TILED_JSON); } function create(){ this.map = this.add.tilemap('level1'); this.map.addTilesetImage('tiles_spritesheet','gameTiles'); this.backgroundLayer = this.map.createLayer('backgroundLayer'); } I have the attached the phaser 2 code, they are a few lines. Thank you! 1-carga-carretera.zip Link to comment Share on other sites More sharing options...
PixelPicoSean Posted March 25, 2018 Share Posted March 25, 2018 function preload(){ this.load.image('gameTiles', 'tiles_spritesheet.png'); this.load.tilemapTiledJSON('level1', 'map.json'); } function create(){ this.map = this.add.tilemap('level1'); var tileset = this.map.addTilesetImage('tiles_spritesheet','gameTiles'); this.backgroundLayer = this.map.createLayer('backgroundLayer', tileset); } Link to comment Share on other sites More sharing options...
Pau Posted March 26, 2018 Author Share Posted March 26, 2018 Thanks! I made it, but the console says "TypeError: this.map.createLayer is not a function". This is the my code, but you can see the whole application it in the attachment: var config = { type: Phaser.AUTO, width: 800, height: 600, scene: { preload: preload, create: create } }; var game = new Phaser.Game(config); function preload(){ this.load.image('gameTiles', 'tiles_spritesheet.png'); this.load.tilemapTiledJSON('level1', 'map.json'); } function create(){ this.map = this.add.tilemap('level1'); var tileset = this.map.addTilesetImage('tiles_spritesheet','gameTiles'); this.backgroundLayer = this.map.createLayer('backgroundLayer', tileset); } coches.zip Link to comment Share on other sites More sharing options...
elleniaw Posted March 26, 2018 Share Posted March 26, 2018 It's either this.map.createDynamicLayer or this.map.createStaticLayer. It depends on if you want to replace/add tiles while active; just go for createStaticLayer for now. Pau 1 Link to comment Share on other sites More sharing options...
Pau Posted March 28, 2018 Author Share Posted March 28, 2018 It is working! Thanks! Link to comment Share on other sites More sharing options...
dekonu Posted July 12, 2018 Share Posted July 12, 2018 Can you clarify how you got it working? I am currently getting the following error: " Uncaught TypeError: Cannot read property 'length' of undefined" When trying to load a map. I'm using webpack to serve if that may have anything to do with it Link to comment Share on other sites More sharing options...
Pau Posted July 13, 2018 Author Share Posted July 13, 2018 In my case, it was to replace the create layer method for createStaticLayer, as elleniaw said. But i think yout problem is different Link to comment Share on other sites More sharing options...
Recommended Posts