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();
}
}
あなたのコードをもっと共有したり、ゲームにリンクすることはできません。これを非常によく似たチュートリアルの実例と比較すると、あなたが投稿したものに間違いはありません。 –
私はこのコードに間違いはありませんが、 'shipCollision()'関数の最初の行に 'debugger; 'を設定してみてください。次に、開発ツールctrl + shift + Jを開いて、その時点で 'this 'の値が何かを確認します。 – BdR