I am working on a new game using the PhaserJS library for HTML5 and am at a loss with a problem I've run into. I'm using the P2 physics engine for basic platform physics and I'm unable to get the world bounds collision to work. Here is my code:
Game.js
function create() {
game.world.setBounds(0, 0, 800, 300);
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.restitution = 0.8;
player.create(game);
player.instance.body.collideWorldBounds = true;
}
Player.js
Player.prototype.create = function(game) {
this.instance = game.add.sprite(100, 100, 'player');
game.physics.p2.enable(this.instance, Phaser.Physics.P2JS);
this.cursors = game.input.keyboard.createCursorKeys();
};
Right now my understanding is that I need to set the world bounds by calling "game.world.setBounds(width, height)" and then check bounds by calling "player.instance.body.collideWorldBounds = true;", but the player sprite is still going right through the boundaries. Any help is greatly appreciated. Thanks!
EDIT: I'm using PhaserJS 2.0.7.