我正在使用适用于 HTML5 的 PhaserJS 库开发一款新游戏,但遇到了一个问题,我不知所措。我将 P2 物理引擎用于基本平台物理,但我无法让世界边界碰撞工作。这是我的代码:
游戏.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;
}
播放器.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();
};
现在我的理解是我需要通过调用“game.world.setBounds(width, height)”来设置世界边界,然后通过调用“player.instance.body.collideWorldBounds = true;”来检查边界,但是玩家精灵仍在通过边界。任何帮助是极大的赞赏。谢谢!
编辑:我正在使用 PhaserJS 2.0.7。