specialspam Posted April 15, 2014 Share Posted April 15, 2014 Hello, I am completely new to Phaser and have just been mucking around with a simple platform canvas and character. I was able to add music and a 'boing' sound for when the character jumps, however, I cannot figure out how to approach adding a walking sound properly when the character walks left or right. With the code below it plays the sound over itself on every update call so when the key is pressed down it just comes out as a loud 'blaarrrrrrr' I have been searching the forums, examples and documentation but just haven't found anything... Does anyone have any tips or pointers they could throw my way? Here is how I load the sound:foot = game.add.audio('foot',1,false);I added the sound in the move left keyboard detection which plays my sprites animation and moves him:if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { // Move to the left player.body.velocity.x = -200; player.animations.play('left'); foot.play('',0,1,false); }Should I be setting up the audio in the animation setup under the create function OR should I limit the amount of times it gets played? sorry I am just a lost beginner! Thanks in advance. Specialspam. Link to comment Share on other sites More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 The 5th parameter to play is 'forceRestart' and it is true by default. If you set this to false then the sounds should stop doing the weird blarrrrr effect.play: function (marker, position, volume, loop, forceRestart) specialspam 1 Link to comment Share on other sites More sharing options...
specialspam Posted April 16, 2014 Author Share Posted April 16, 2014 Thank you rich, much appreciated, and it was staring at me the whole time.... http://docs.phaser.io/Phaser.Sound.html#play Cheers. Link to comment Share on other sites More sharing options...
Recommended Posts