JSFiddle - React, Tailwind, and code Playground
by Gaurav D
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script>
<div id="phaser"></div>
JavaScript
var game = new Phaser.Game(500, 500, Phaser.CANVAS, 'phaser', {
preload: preload,
create: create,
update: update
});
function preload() {}
function create() {
let x = 0;
let y = 0;
//If center = false, implying x = y = 0, the body collides with the world boundary and the collision resolver will push it out with an impulse.
let center = true;
if (center) {
x = 250;
y = 250;
}
this.game.stage.disableVisibilityChange = true;
this.physics.startSystem(Phaser.Physics.P2JS);
this.physics.p2.restitution = 0.63;
this.physics.p2.gravity.y = 80;
this.physics.p2.applyGravity = true;
this.ball = this.game.add.sprite(x, y);
this.game.physics.p2.enable(this.ball);
this.ball.body.setCircle(50);
this.ball.body.damping = 0.5;
this.ball.body.fixedRotation = true;
this.ball.anchor.x = 0.5;
this.ball.anchor.y = 0;
this.ball.body.debug = true;
}
function update() {}