Jcook894 Posted January 8, 2017 Share Posted January 8, 2017 Im adding audio to my game and I'm having trouble playing the audio just once when my lands after a jump. I keep on getting this redundant and unpleasant sound from the game and was wondering if there is a method of just playing the audio just once when the player lands. Here is my code : update: function(){ // Basically an event listener for the keys. cursors = game.input.keyboard.createCursorKeys(); var onPlatform = game.physics.arcade.collide(player,platforms); player.body.velocity.x = 0; if(cursors.right.isDown){ player.scale.x = 1; player.body.velocity.x = 150; player.animations.play('right', 10,true); facing = 'right'; } else if(cursors.left.isDown){ player.body.velocity.x = -150; player.scale.x = 1; player.animations.play('left', 10, true); facing = 'left'; } else { if(facing != 'idle') { player.animations.stop(); if (facing == 'left') { player.frame = 4; } if (facing == 'right'){ player.frame = 5; } else { player.frame = 4; } facing = 'idle'; } } if (cursors.up.isDown && player.body.touching.down && onPlatform ){ player.body.velocity.y = -400; jumpSnd.play(); } if(player.body.touching.down && onPlatform){ landSnd.play(); } if (fireButton.isDown){ fireGun(); gunSound.play(); } And here is my repo if anyone would like to play : https://github.com/Jcook894/Side_Scroller_game Link to comment Share on other sites More sharing options...
PhasedEvolution Posted January 8, 2017 Share Posted January 8, 2017 put if (fireButton.isDown){ fireGun(); gunSound.play(); } in you create function. Link to comment Share on other sites More sharing options...
Jcook894 Posted January 8, 2017 Author Share Posted January 8, 2017 59 minutes ago, PhasedEvolution said: put if (fireButton.isDown){ fireGun(); gunSound.play(); } in you create function. I put both of those if statements into the create function and its still playing, Am I supposed to pass it in parameters? Link to comment Share on other sites More sharing options...
PhasedEvolution Posted January 9, 2017 Share Posted January 9, 2017 Oh... Only noticed it now. If you want to fire once you should use "firebutton.onDown.add(function () { ... Your code... })" Jcook894 1 Link to comment Share on other sites More sharing options...
Jcook894 Posted January 9, 2017 Author Share Posted January 9, 2017 12 hours ago, PhasedEvolution said: Oh... Only noticed it now. If you want to fire once you should use "firebutton.onDown.add(function () { ... Your code... })" Thanks a lot ! That totally worked Link to comment Share on other sites More sharing options...
Recommended Posts