2016-04-17 31 views
0

私はPhaser HTML5ゲームエンジンを使用してインベーダーのようなゲームを作成しています。私はすでにそれとはまだありません手掛かりに2日間を過ごしてきたこのCannot read property 'getFirstExists' of undefinedエラーに未定義のプロパティ 'getFirstExists'を読み取ることができません

ラン私は「船」と「敵」の衝突試験を追加しようとしている...

。 :(

助けてください。ありがとうございます。

var play = function(game) {} 

play.prototype = { 
    create: function(){ 
     .... 
     // Add an explosion group 
     this.explosions = this.game.add.group(); 
     this.explosions.enableBody = true; 
     this.explosions.physicsBodyType = Phaser.Physics.ARCADE; 
     this.explosions.createMultiple(15, 'explosion'); 
     this.explosions.setAll('anchor.x', 0.5); 
     this.explosions.setAll('anchor.y', 0.5); 
     this.explosions.forEach(function(explosion) { 
      explosion.animations.add('explosion', [0, 1, 2], 10 , false); 
     }); 
    }, 

    update: function(){ 
     .... 
     this.game.physics.arcade.overlap(this.ship, this.enemyGroupSizeL,  this.shipCollision, null, this); 
    }, 

    shipCollision: function(s, e) { 
     this.explosion = this.explosions.getFirstExists(false); // ERROR 
     this.explosion.reset(e.body.x + e.body.halfWidth, e.body.y + e.body.halfHeight); 
     this.explosion.body.velocity.y = e.body.velocity.y; 
     this.explosion.alpha = 0.7; 
     this.explosion.play('explosion', 30, false, true); 
     e.kill(); 
    } 
} 
+0

あなたのコードをもっと共有したり、ゲームにリンクすることはできません。これを非常によく似たチュートリアルの実例と比較すると、あなたが投稿したものに間違いはありません。 –

+0

私はこのコードに間違いはありませんが、 'shipCollision()'関数の最初の行に 'debugger; 'を設定してみてください。次に、開発ツールctrl + shift + Jを開いて、その時点で 'this 'の値が何かを確認します。 – BdR

答えて

0

私はフェイザーでゲームを作るためにtypescriptですを使用しています。私は、爆発物がある前に、その理由の一つは、そのフェイザーエンジンコールアップデート機能(自動呼び出し)することができると思います作成された。

this.game.physics.arcade.overlap(this.ship, this.enemyGroupSizeL, this.shipCollision, null, this); 
0123前

if(this.explosion !+ undefined) 

を追加します。更新機能では

です。

関連する問題