How to make player restrict of boundries only left right not up and down in phaser js game?

Viewed 56

How to make player restrict of boundries only left right not up and down in phaser js game? enter image description here

1 Answers

You can set the custom world bounds, with the function this.physics.world.setBounds(...). Here a link to the documentation.

So, you just would have to put this line, into your code:

`this.physics.world.setBounds(0, 0, widthOfTheGame, heightOfTheGame, true, true, false, true);`.

in the create function.

following the documenttation setBounds(x, y, width, height [, checkLeft] [, checkRight] [, checkUp] [, checkDown])

The third false is for the world-bounds-top, and so no colliding should occure.

Related