Jump to content

Getting an error when converting TilemapLayer with matter


Phillor
 Share

Recommended Posts

Hey folks,

in the last couple of days I played around with phaser 3. On Sunday I tried to implement Tilemaps in the game I plan to make with phaser.

I want do all of this with the matter physics engine. Until now I'm really pleased working with phaser :)

But as I said Sunday I got stuck and I was not able to figure this out. Maybe you guys can help me.

I'll just paste the code in here:

 

gameScene.preload = function() {
	this.load.image('ship', 'assets/ship.png');
	this.load.image('tileset', 'assets/tileset.png');
	this.load.tilemapTiledJSON('map', 'assets/tilemap.json');
};

gameScene.create = function() {
	
	

	var map = this.make.tilemap({ key: 'map' });

	var tileset = map.addTilesetImage('tileset');

	var seaLayer = map.createDynamicLayer("sea", tileset, 0, 0);
	var surfaceLayer = map.createDynamicLayer("surface", tileset, 0, 0);
	var mainlandLayer = map.createDynamicLayer("mainland", tileset, 0, 0);
	var aboveLayer = map.createDynamicLayer("above", tileset, 0, 0);
	
	console.log(mainlandLayer);
	mainlandLayer.setCollisionByProperty({ collides: true });

	this.matter.world.convertTilemapLayer(seaLayer);
	this.matter.world.convertTilemapLayer(surfaceLayer);
	this.matter.world.convertTilemapLayer(mainlandLayer);
	this.matter.world.convertTilemapLayer(aboveLayer);

	
};

I always run into the following error:

Quote

TypeError: this.tileset.getTileCollisionGroup is not a function

I'm creating the tilemap with Tiled. I heard that in version 1.2 Tiled changed something about the exporting of the maps so I tried the version 1.1.6. But I still get the quoted error.

I added a custom property to the tileset which is called "collides" (which is a boolean) and I was able to figure out that the lines where I call "this.matter.world.convertTilemapLayer" will cause this error but only if the stated Layer in this line has tiles in it that have this custom property flagged "true".

 

I'm really running out of ideas what could cause this error message. Maybe you can give me a little hint :)

Cheers,

Phil

Link to comment
Share on other sites

So I just figured out that all of this is working fine in Phaser 3.13.

I saw that quite a bit changed in version 3.14 about Tilemaps and static and dynamic Layer.

Does anyone know what I did wrong there or is it a bug?

 

//edit:

Seems to be a bug I think. The function responsible for getting the collision group of the tiles is expecting a single reference of the tileset while getting an array.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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