JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/phaser/2.0.5/phaser.min.js"></script>
<div id="gameArea"> </div>
CSS
#gameArea {
width: 500px;
margin: auto;
margin-top: 50px;
}
JavaScript
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'gameArea');
var App = {};
App.main = function() { };
App.main.prototype = {
create: function() {
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.gravity.y = 400;
var sp1 = this.game.add.sprite(250, 300, null);
game.physics.p2.enable(sp1, true);
sp1.body.static = true;
sp1.body.clearShapes();
sp1.body.addRectangle(10, 200, 0, 0, 0);
var sp2 = this.game.add.sprite(200, 150, null);
game.physics.p2.enable(sp2, true);
sp2.body.clearShapes();
sp2.body.addRectangle(300, 20, 0, 0, 0);
sp2.body.addRectangle(100, 100, 150, 0, 0);
sp2.body.adjustCenterOfMass();
}
};
game.state.add('main', App.main);
game.state.start('main');