Jump to content

Bullets(group) acting weird


ctmartinez1992
 Share

Recommended Posts

So i have this method that creates the bullets

createBullets() {            this.bullets.createMultiple(30, 'bullet');            this.bullets.setAll('anchor.x', 0.5);            this.bullets.setAll('anchor.y', 0.5);            this.bullets.setAll('outOfBoundsKill', true);}

and then i update them here to fire the bullets

        update() {                    if (this.fireKey.isDown) {                        if (this.game.time.now > this.firingTimer) {                            this.fire();                        }                    }                    if (this.game.physics.collide(this.bullets, this.enemies, this.bulletCollidesEnemy)) {                        this.score++;                        this.scoreText.content = "Score " + this.score;                    }                }        }

And the collide handler and the fire mechanism

        bulletCollidesEnemy(bu, bo) {            bu.kill();            bo.destroy()        }        fire() {            var bullet: Phaser.Sprite = this.bullets.getFirstExists(false);            if (bullet) {                bullet.reset(this.player.x + 12, this.player.y - 6);                bullet.body.velocity.y = -300;                this.firingTimer = this.game.time.now + this.fireTimeControl;            }        }

This sometimes works well and the next second its broken and then works again, here, you can see it for yourself: https://dl.dropboxusercontent.com/u/52790690/HTML5%20GD/game4/game4/default.htm

If you hold space it will fire half a dozen of bullets and then some of them will just get stuck and not move at all. Eventually you will run out of bullets in the group because they are all stuck in there.

 

I need help on this one, i can't understand what i am possibly doing wrong.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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