Question
Jump trough (up and down) platform in Phaser 3
I followed this tutorial which works great for jumpin up and landing on top of the platform.
I've setup the collision disable trick (so players can also jump down through) which also works great.
My issue is: This applies to ALL the Tiled layers.
How can you check if the tiles the character is standing on is actually from a specific layer from your Tiled map?
My current setup:
// Import map from Tiled
this.map = this.make.tilemap({ key: 'myBeautifulMap' });
this.platform = this.map.createLayer('platform', this.tileset);
// Apply collision to ALL tiles from this Layer
this.platform.setCollisionByExclusion(-1, true);
// disable one side collision so character can jump up trough it
this.platform.forEachTile(tile => {
if (tile.index > 0){
tile.setCollision(false, false, true, false);
}
});
// Allow jump down
// This part shoudl check if the tiles the character is standing on are part of the 'platform' Layer
if (this.keyboard.S.isDown) {
this.body.checkCollision.down = false;
this.scene.time.addEvent({
delay: 400,
callback: () => {
this.body.checkCollision.down = true;
},
callbackScope: this
});
}