Jump to content

Audio looping constantly, getting annoying sound >.<


Jcook894
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...