damager Posted November 13, 2017 Share Posted November 13, 2017 Hi, i'm going to create phaser runner game, but i stuck with one problem. I create a bullets like this: this.bullets = this.game.add.group(); this.bullets.name = 'bullets'; this.bullets.enableBody = true; this.bullets.physicsBodyType = Phaser.Physics.P2JS; this.bullets.createMultiple(100, 'playerBullet', 0, false); this.bullets.forEach(function(child){ child.body.setRectangle(25, 35, 0, 0); child.name = "bullet"; child.anchor.set(0.5, 0.5); child.body.motionState = Phaser.Physics.P2.Body.KINEMATIC; //child.body.debug = true; child.body.onBeginContact.add(SimpleGame.prototype.onBulletBeginContact, this); }, this); this.bullets.setAll('outOfBoundsKill', true); this.bullets.setAll('checkWorldBounds', true); and creating them 5 times at second this.shotTime.loop(200, SimpleGame.prototype.shotTheEnemies, this); shotTheEnemies(e:Phaser.TimerEvent) { let bullet: Phaser.Sprite; for (var i = 0; i < 2; i++) { bullet = this.bullets.getFirstExists(false); if (bullet) { bullet.reset(this.player.x -14+(28*i), this.player.y - this.player.height/2-20); bullet.body.moveUp(900); //console.log(bullet.body.) } } } But in time when bullets hit enemy and i use bullet.kill() some of pool bullets don't have speed(And i can't manipulate them till i use bullet.kill again, BUT i don't know which bullets are lag). That's not happening when bullets hit the world bounce. Please help) Link to comment Share on other sites More sharing options...
damager Posted November 13, 2017 Author Share Posted November 13, 2017 That's not object pool bug, i've found that bug appears when i use bullet.kill() right at the moment when collision is started (OR i'm wrong, cause hard to recreate bug when i slowly move the ship that fires bullets). But i don't know how to fix this and why it appears in that way...Can i somehow clear colliding forces when i use bullet.kill() function? Does someone know? (Plz help, my brain is literally blowing up) Thanks) Link to comment Share on other sites More sharing options...
damager Posted November 14, 2017 Author Share Posted November 14, 2017 20 hours fighting with this "bug"...but fixed. Problem was in this line this.bullet = this.bullets.getFirstExists(false); That is correct version: this.bullet = this.bullets.getFirstExists(false, false, this.player.x -14+(28*i), this.player.y - this.player.height/2); i don't know why, but if i don't set position in this method, and set it up later this "bug" shows up. Link to comment Share on other sites More sharing options...
Recommended Posts