Have you started P2 running?
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.enable(sprite);
Also make sure you're using a version of Phaser with P2 bundled in it.
Вопрос
I'm trying to enable the P2JS physics engine for a sprite in my game, and game.physics.enable
only seems to work for the Arcade physics engine. What's going on here?
Example:
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…}
Решение
Have you started P2 running?
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.enable(sprite);
Also make sure you're using a version of Phaser with P2 bundled in it.
Другие советы
u should try this it will work
game.physics.startSystem(Phaser.Physics.P2JS);
sprite.physicsBodyType = Phaser.Physics.P2JS;
game.physics.p2.enable(sprite);