Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取属性';getFirstExists';未定义的_Javascript_Game Engine_Phaser Framework - Fatal编程技术网

Javascript 无法读取属性';getFirstExists';未定义的

Javascript 无法读取属性';getFirstExists';未定义的,javascript,game-engine,phaser-framework,Javascript,Game Engine,Phaser Framework,我正在使用Phaser HTML5游戏引擎创建一个类似入侵者的游戏 当我试图为“船”和“敌人”添加碰撞测试时,遇到此无法读取未定义的属性“getFirstExists”错误 我已经花了两天时间在这件事上,仍然没有任何线索( 请帮忙,谢谢 var play = function(game) {} play.prototype = { create: function(){ .... // Add an explosion group this.

我正在使用Phaser HTML5游戏引擎创建一个类似入侵者的游戏

当我试图为“船”和“敌人”添加碰撞测试时,遇到此
无法读取未定义的属性“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();
    }
 }

我使用typescript在Phaser中制作游戏。我认为其中一个原因可能是Phaser引擎在创建爆炸对象之前调用了更新函数(自动调用)

以前

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

在你的更新功能中。

我不认为你可以分享更多的代码或游戏链接?将此与一个非常类似的教程中的工作示例进行比较,我看不出你发布的内容有任何错误。我也看不出此代码有任何错误,但你可以尝试将
调试器;
设置为的第一行ode>shipCollision()函数。然后打开开发工具ctrl+shift+J,查看此时此的值。
this.game.physics.arcade.overlap(this.ship, this.enemyGroupSizeL, this.shipCollision, null, this);