Reputation: 3
I'm new to Phaser and I need your help. I want to make my character's projectals to bounce off of walls. So far in create() I've got something like this:
game.physics.startSystem(Phaser.Physics.ARCADE);
ball = game.add.group();
ball.enableBody = true;
ball.setAll('body.collideWorldBounds', true);
Later on in the update():
fire.onDown.add(function () {
var bullet = ball.create(Char1.x,Char1.y,'ball');
if(bullet){
bullet.body.velocity.set(0,-400);
}
Upvotes: 0
Views: 97
Reputation: 748
Make sure you enable physics for your bullet, then set bounce like this:
game.physics.arcade.enable(bullet)
// set the bounce energy, 1 is 100% energy return
bullet.body.bounce.set(1);
And this line will make the game world bounceable:
bullet.body.collideWorldBounds = true;
Upvotes: 2