Jump to content

Group of enemies firing issue


kuka93
 Share

Recommended Posts

Hi, I'm new with Phaser and I'm developing a small platformer game. I'm creating a group of enemies that should open fire every 1-2 seconds, but the problem is that only one of those shoots.

In the create method my code is:

// Creating bullets for robot
this.lasersRobot = this.game.add.group();
this.lasersRobot.enableBody = true;
this.lasersRobot.physicsBodyType = Phaser.Physics.ARCADE;
this.lasersRobot.createMultiple(bulletsRobot, 'bulletRobot');
this.lasersRobot.callAll('events.onOutOfBounds.add', 'events.onOutOfBounds', this.resetLaserRobot);
this.lasersRobot.callAll('anchor.setTo', 'anchor', 0.5, 1.0);
this.lasersRobot.setAll('checkWorldBounds', true);


// Creating the group of enemies
this.enemiesRobot = this.game.add.group();
this.map.createFromObjects('ObjectLayer', 149, 'enemyRobot', 0, true, false, this.enemiesRobot);
this.enemiesRobot.physicsBodyType = Phaser.Physics.ARCADE;
this.enemiesRobot.forEach(this.setupEnemiesRobot,this);

then, in the update method, the snippet of the code for the enemies' shooting is:

if (this.game.time.now > nextFire){
   nextFire = this.game.time.now + fireRate;
   var laser = this.lasersRobot.getFirstExists(false);
   if (laser) {
      laser.reset(enX-10, enY);
      laser.body.velocity.x = -300;
      this.shootSound.play();
    }
}

I have 8 enemies, but only the first one opens fire every 1 second.. Can anyone help me?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...