PixelProgrammer Posted February 2, 2017 Share Posted February 2, 2017 Currently, in my game. I've done the following if (player.fireButton.isDown) { //firing straight up player.weapon.fireAngle = Phaser.ANGLE_UP; player.weapon.fire(); this.shootSfx.play(); } The issue with this is that when I hold down the `fireButton` the first millisecond of the sound is played on a loop. Basically, the sound just keeps resetting. How do I set it up so that it has to play the full sound clip before starting again? Also, are there any Phaser examples of sounds and weapons being used together? Link to comment Share on other sites More sharing options...
rroylance Posted February 2, 2017 Share Posted February 2, 2017 For checking if a sound is playing; https://phaser.io/docs/2.6.2/Phaser.Sound.html#isPlaying. So you could possibly do ... if (player.fireButton.isDown) { //firing straight up player.weapon.fireAngle = Phaser.ANGLE_UP; player.weapon.fire(); if (!this.shootSfx.isPlaying) { this.shootSfx.play(); } } You could also potentially use https://phaser.io/docs/2.6.2/Phaser.Weapon.html#onFire event to only play the sound when a bullet is successfully fired (even though you call fire() a bullet may not be fired due to timing, count limit, etc...) samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts