Pau

Load tilemap

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

Share this post


Link to post
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);	
}

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.