arun Posted May 6, 2018 Share Posted May 6, 2018 Hi friends, I don't understand the following code . please help me this.bullets = []; this.nextShotAt = 0; this.shotDelay = 100; fire: function() { if (this.nextShotAt > this.time.now) { return; } this.nextShotAt = this.time.now + this.shotDelay; var bullet = this.add.sprite(this.player.x, this.player.y - 20, 'bullet'); bullet.anchor.setTo(0.5, 0.5) ; this.physics.enable(bullet, Phaser.Physics.ARCADE); bullet.body.velocity.y = -500; this.bullets.push(bullet); } Link to comment Share on other sites More sharing options...
PsichiX Posted May 7, 2018 Share Posted May 7, 2018 this code ensures that there will be 100 ms delay between fire shots. it also creates a sprite and sets its body velocity so bullet will use physics for movement. the stupid part there is that this code does not give a f*** about destroying bullets, so i hope the full source that you use have this. thanks for me for being helpful. b10b 1 Link to comment Share on other sites More sharing options...
Recommended Posts