Jump to content

Space Invaders - Next bullet not moving after previous one collides


GooseZA
 Share

Recommended Posts

Hi all, 

 

I've just started using Phaser today and I'm trying to make a simple space invaders game.

 

In my create function I have the following for my bullet group: 

//player bullets pool        playerBullets = game.add.group();        playerBullets.createMultiple(30, "laserGreen");        playerBullets.setAll('anchor.x', 0.5);        playerBullets.setAll('anchor.y', 1);        playerBullets.setAll('outOfBoundsKill', true);

Then on my player object, I have this method to fire a laser which works perfectly

 this.fireLaser = function () {            var bullet = playerBullets.getFirstExists(false);            if (bullet) {                bullet.reset(this.sprite.x, this.sprite.y - 30);                bullet.body.velocity.y = -400;                bulletTime = game.time.now + 200;            }        };

in my Update function, I check for collisions between my bullet group and my enemies group and call the following

  function enemyHit(bullet, enemy) {        bullet.kill();        enemy.kill();    }

This all works perfectly. My bullets fire and when they collide with the enemy they both disappear. 

 

BUT, the very next bullet AFTER a collision occurs just freezes on my player model. It doesn't move. When I then set its velocity from the Chrome dev tools it will start moving again but for some reason when it is created it's velocity is 0. This happens for only the FIRST bullet fired directly after EACH collision.

 

Any ideas why the velocity isn't being set even though it's going through the same fireLaser method? I'm stumped. 

 

I've attached what I've made so far

Shooter2.zip

Link to comment
Share on other sites

I have the exact same problem.

 

Is it a known bug or are we just doing things the wrong way ?

 

 

It worked well under 1.1.3 and when I upgraded to 1.1.4, the callback didn't trigger anymore.

And now, on 1.1.5, there is this bug with the velocity after killing a sprite.

 

(I'm totally new to game dev & phaser so maybe I am the problem here)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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