문제

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top