1

I am using Tiled to create my levels in Phaser 3. I have my level, and the platforms load in fine, however, my player goes right through them. How do I add matter bodies to all of my platforms that are loaded?

Code for my platforms:

        //Create tilemap
        const map = this.make.tilemap({key: 'map'});
        //Create tileset
        const tileset = map.addTilesetImage('Assets_City', 'tiles');
        const platforms = map.createStaticLayer('Ground', tileset, 0, 200);
Robert Smith
  • 673
  • 10
  • 25

1 Answers1

1

After the line const platforms = map.createDynamicLayer('Ground', tileset, 0, 0);, add the following line:

platforms.setCollisionBetween(1, 50);

For your reference:

//Create tilemap
const map = this.make.tilemap({key: 'map'});
//Create tileset
const tileset = map.addTilesetImage('Assets_City', 'tiles');
const platforms = map.createDynamicLayer('Ground', tileset, 0, 0);
platforms.setCollisionBetween(1, 50);

EDIT:

OP couldn't make to run with my original solution because he removed these lines by error:

platforms.setCollisionByProperty({ collides: true});
this.matter.world.convertTilemapLayer(platforms);
Manuel Abascal
  • 5,616
  • 5
  • 35
  • 68