Search the Community
Showing results for tags 'body.bounce'.
-
So we have sprite moving left right and the aim is to make it stop when hit a "invisible" wall. Let's presume that the x coordinate checks are 0px and 300px, so: if(game.input.keyboard.isDown(Phaser.Keyboard.A)) { paddle.body.velocity.x = -paddleSpeed; } else if(game.input.keyboard.isDown(Phaser.Keyboard.D)) { paddle.body.velocity.x = paddleSpeed; }and after checking some Phaser source i came up with this: if(paddle.x < paddle._cache.halfWidth) { paddle.x = paddle._cache.halfWidth; paddle.body.velocity.x *= -paddle.body.bounce.x; } if(paddle.x > game.world.width - paddle._cache.halfWidth) { paddle.x = game.world.width - paddle._cache.halfWidth; paddle.body.velocity.x *= -paddle.body.bounce.x; } If I use: paddle.body.collideWorldBounds = true; //like in the examples it-s all KO no bouncing/jitter when paddle hit the walls And since this is the code for checkWorldBounds: if (this.x < this.game.world.bounds.x){this.x = this.game.world.bounds.x;this.velocity.x *= -this.bounce.x;}else if (this.right > this.game.world.bounds.right){this.x = this.game.world.bounds.right - this.width;this.velocity.x *= -this.bounce.x;}I used the same approach... but still when it hit the right or left border the sprite passes the border and then it's positioned back ... you can check it, here: http://mihail.ilinov.eu/games/PhaserBreakoutJSBuggy/ Just press "A" and "D" for moving left and right and hit the wall you will see the problem... Also what's the deal with: body.bounce