2014-10-28 93 views
1

我重構了我的代碼以便使用狀態和類。代碼更清晰,但與onBeginContact關聯的回調不再被調用。沒有課,它按預期工作。onBeginContact未派發

在Boot.js:

this.game.physics.startSystem(Phaser.Physics.P2JS); 

在Game.js:

this.ship = this.game.add.sprite(200, 200, 'ship'); 
this.ship.animations.add('propulse', [1, 2, 3]); 
this.game.physics.p2.enable(this.ship, false); 
this.ship.body.addPolygon({}, 30, 35 , 0, 35 , 14, 5); 
this.ship.body.onBeginContact.add(this.hitWall, this); 

hitWall不叫。我曾嘗試使用一個簡單的功能,但同樣的問題。如果您需要更多信息,請詢問。

回答

0

行:

this.game.physics.startSystem(Phaser.Physics.P2JS); 

應在Game.js了。

+1

更具體地說,物理系統在遊戲狀態改變時被銷燬。這就是物理系統需要重新啓動並進行相應配置的原因。 – kctang 2014-11-11 23:45:06