Jump to content

Load tilemap


Pau
 Share

Recommended Posts

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

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

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

  • 3 months later...

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

 Share

  • Recently Browsing   0 members

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