通过 overlap() 的碰撞检测在 phaser.io 中不起作用

Collision detection via overlap() not working in phaser.io

请注意,我完全使用 Phaser.io 创建了以下代码。

所以我创建了一个敌人组和一个武器组(使用内置 game.add.weapon())。

我检查了这两组之间的重叠,但由于某种原因,hitEnemy() 函数从未被触发。

我相信这与使用内置武器组有关,但我无法弄清楚它到底是什么。

var playState = {
    preload: function () {
        game.load.image('player', 'assets/player.png');
        game.load.image('enemy', 'assets/enemy.png');
        game.load.image('floor', 'assets/floor.png');
        game.load.image('bullet', 'assets/bullet.png');
    },

    create: function () {
        game.stage.backgroundColor = '#000000';
        game.physics.startSystem(Phaser.Physics.ARCADE);
        game.renderer.renderSession.roundPixels = true;

        this.cursors = game.input.keyboard.createCursorKeys();
        this.fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

        this.createBullets();

        this.createEnemies(game.width/2, 120, 'enemy');
     },
     update: function () {
        game.physics.arcade.collide(this.player, this.floor);
        game.physics.arcade.overlap(this.weapon, this.enemies, this.hitEnemy, null, this);
     },
     createBullets: function () {    
        this.weapon = game.add.weapon(30, 'bullet');
        this.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
        this.weapon.bulletSpeed = 850;
        this.weapon.fireRate = 100;
        this.weapon.trackSprite(this.player);
    },
    createEnemies: function (x,y ,size) {
        this.enemies = game.add.group();
        this.enemies.enableBody = true;
        this.enemies.physicsBodyType = Phaser.Physics.ARCADE;

        var asteroid = this.enemies.create(x, y, size);
        asteroid.anchor.setTo(0.5,0.5);
        asteroid.name = "enemy1";
        asteroid.body.immovable;
    },
    hitEnemy: function (player, enemy) {
        this.enemy.kill();
        console.log("Hit");
    },
};

找到解决方案。

而不是检查与 this.enemies 和 this.weapon 的重叠。我应该检查与 this.enemies 和 this.weapon.bullets

的碰撞