Я создаю похожую на захватчик игру, используя игровой движок Phaser HTML5.Невозможно прочитать свойство 'getFirstExists' of undefined
Run в эту Cannot read property 'getFirstExists' of undefined
ошибку, когда я пытаюсь добавить тест коллизий для «корабля» и «врагов» ...
Я уже провел два дня на нем и до сих пор никаких намеков. :(
Пожалуйста, помогите. Спасибо.
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(). Затем откройте инструменты разработчика ctrl + shift + J, чтобы узнать, что такое значение 'this' в этой точке. – BdR