How to make One Way  Platforms in Phaser 3.60

How to make One Way Platforms in Phaser 3.60

Working with Phaser 3.60 and Tiled Map Editor

What's up, Wizards! Today, you will be learning how to make One-Way Platforms in Phaser 3.60. To get this tutorial to work, you should have a working tilemap setup in your Phaser project made using the Tiled Map Editor. If you do not have a tilemap setup in Phaser then you can refer to our previous blog on "How to make Tilemaps in Phaser 3.60".

⚠ Note: This blog is the continuation of our previous blog. So for this to work, you need to have the same setup that we had in our previous blog, made using Tiled Map Editor and Phaser 3.60. Have fun!

Firstly, in the Tiled Map Editor, you have set a custom property "OneWay" to the "One-Way Platform" tile make sure the property is checked. Then, add the following lines to your platform code in Phaser 3.60:

create() {
    const myMap = this.make.tilemap({ key: 'map' });
    const tileset = myMap.addTilesetImage('tilesheet', 'tiles');
    const platforms = myMap.createLayer('Platforms', tileset, 0, 0);
    platforms.setCollisionByExclusion(-1, true);
    platforms.forEachTile(tile => {
            if (tile.properties["OneWay"]) {
                tile.setCollision(false, false, true, false);
            }
    });
}

Note: Before copying this code, make sure that you have imported and preloaded all the necessary files. If you have not, you may refer to our previous blog, "How to make Tilemaps in Phaser 3.60".

And that's it! Your one-way platforms are good to go! If you have faced any problems while following this tutorial, feel free to comment below. I will try my best to solve your problems.

Happy Coding!