我正在尝试在我的游戏中为精灵启用P2JS物理引擎,game.physics.enable
似乎只适用于Arcade物理引擎。这是怎么回事?
示例:
player.body
//=> null
game.physics.enable(player, Phaser.Physics.P2JS, true)
//=> undefined
player.body
//=> null
game.physics.enable(player, Phaser.Physics.NINJA, true)
//=> undefined
player.body
//=> null
game.physics.enable(player, Phaser.Physics.ARCADE, true)
//=> undefined
player.body
//=> b.Physics.Arcade.Body {sprite: Player, game: b.Game, type: 0, offset: b.Point, position: b.Point…}
答案 0 :(得分:4)
你开始P2跑吗?
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.enable(sprite);
另外请确保您使用捆绑了P2的Phaser版本。
答案 1 :(得分:2)
你应该尝试一下它会起作用
game.physics.startSystem(Phaser.Physics.P2JS);
sprite.physicsBodyType = Phaser.Physics.P2JS;
game.physics.p2.enable(sprite);