kekkorider Posted September 1, 2016 Share Posted September 1, 2016 Hi everyone, I'm following a tutorial about creating a shoot 'em up with Phaser but I got stuck when creating a power up that allows you to shoot multiple bullets at a time. As Richard Davey says it should be as simple as calling the .fire() method multiple times but it doesn't work, only the first call to .fire() gets executed no matter what. Here's my code: for ( var i = 0; i < this.weaponLevel; i++ ) { // Left bullets var left = new Phaser.Point(this.player.position.x - 10*i, this.player.position.y - 20); this.weapon.fireAngle = -95 - i*10; this.weapon.fire(left); // Right bullets var right = new Phaser.Point(this.player.position.x + 10*i, this.player.position.y - 20); this.weapon.fireAngle = -85 + i*10; this.weapon.fire(right); } I've googled a lot and unfortunately I found nothing. Thanks in advance. Link to comment Share on other sites More sharing options...
samme Posted September 2, 2016 Share Posted September 2, 2016 I'd guess the second bullet would exceed the weapons fireRate (default: 100ms). BTW you can use weapon.fireAtXY(x, y) instead of creating a point to fire at. kekkorider 1 Link to comment Share on other sites More sharing options...
kekkorider Posted September 2, 2016 Author Share Posted September 2, 2016 Didn't even think about the fireRate property, I think you're right @samme .__. So, my weapon cannot shoot more then one bullet every 100ms no matter what, I must find a workaround. (BTW, the Phaser.Point objects I create are the from property of the fire() method, so I don't need to use the fireAtXY() method ) Link to comment Share on other sites More sharing options...
kekkorider Posted September 2, 2016 Author Share Posted September 2, 2016 Ok, I figured it out, it's quite simple when you know what's the problem. When my power up is active I set the weapon .fireRate property to 0, in order to shoot multiple bullets at a time, then the fire rate is managed "the old way" using this.time.now + an additional time (in my case it's the this.WEAPON_FIRE_RATE variable). After the power up effect finishes I set: the weapon's fireRate property back to its original value the this.weaponLevel variable back to 0 in order to shoot "normally" if ( this.weaponLevel === 0 ) { this.weapon.fire(); } else { // This allows us to shoot multiple bullets at a time this.weapon.fireRate = 0; if ( this.nextShotPowerUpAt > this.time.now ) return; this.nextShotPowerUpAt = this.time.now + this.WEAPON_FIRE_RATE; for ( var i = 0; i < this.weaponLevel; i++ ) { // Left bullets var left = new Phaser.Point(this.player.position.x - (10+i*6), this.player.position.y - 20); this.weapon.fireAngle = -95 - i*10; this.weapon.fire(left); // Right bullets var right = new Phaser.Point(this.player.position.x + (10+i*6), this.player.position.y - 20); this.weapon.fireAngle = -85 + i*10; this.weapon.fire(right); } } Link to comment Share on other sites More sharing options...
rich Posted September 8, 2016 Share Posted September 8, 2016 https://github.com/photonstorm/phaser/commit/c42c447bfbfc875cc0b017ceb09a5c909bf9f4c4 Link to comment Share on other sites More sharing options...
kekkorider Posted September 8, 2016 Author Share Posted September 8, 2016 Thanks a lot @rich, really appreciated that Link to comment Share on other sites More sharing options...
Recommended Posts