arun Posted May 19, 2017 Share Posted May 19, 2017 hi, i am following phaser tutorial . but, i don't understand the fire: function() code. please help me create: function () { ... this.bullets = []; // Add an empty sprite group into our game this.bulletPool = this.add.group(); // Enable physics to the whole sprite group this.bulletPool.enableBody = true; this.bulletPool.physicsBodyType = Phaser.Physics.ARCADE; // Add 100 'bullet' sprites in the group. // By default this uses the first frame of the sprite sheet and // sets the initial state as non-existing (i.e. killed/dead) this.bulletPool.createMultiple(100, 'bullet'); // Sets anchors of all sprites this.bulletPool.setAll('anchor.x', 0.5); this.bulletPool.setAll('anchor.y', 0.5); // Automatically kill the bullet sprites when they go out of bounds this.bulletPool.setAll('outOfBoundsKill', true); this.bulletPool.setAll('checkWorldBounds', true); this.nextShotAt = 0; fire: function() { if (this.nextShotAt > this.time.now) { return; } if (this.bulletPool.countDead() === 0) { return; } this.nextShotAt = this.time.now + this.shotDelay; // Find the first dead bullet in the pool var bullet = this.bulletPool.getFirstExists(false); // Reset (revive) the sprite and place it in a new location bullet.reset(this.player.x, this.player.y - 20); bullet.body.velocity.y = -500; }, Link to comment Share on other sites More sharing options...
Recommended Posts