Jump to content

changing from one sound to another sound seems broken


kurtfriedrich
 Share

Recommended Posts

I think if you have done these lines of code:

this.load.audio('staraudio', 'assets/starAudio.mp3');
this.load.audio('jump', 'assets/jump.mp3');
 
then you can do:
this.sound = this.sound.add('jump');
this.sound.play();
 
and then after a user does something a little latter
this.sound = this.sound.add('staraudio');
this.sound.play();
 
the first one works, the second .add gets me 
StarsGame.js:18 Uncaught TypeError: this.sound.add is not a function
 
i even coded a  function to change sounds;
 
changeSound = function (number) {
    if(number ===1){
         this.sound = this.sound.add('jump');
    }
    if(number ===2){
        this.sound = this.sound.add('staraudio');
    }
}
 
and I can call that from various places in my game  (once) and then do a this.sound.play();
if I call it only once, using either a 1 or 2, then that sound works throughout the game, but
if I try and call it a 2nd time to change the sound (or even just passing in the same int as the 1st time,
I get 
StarsGame.js:18 Uncaught TypeError: this.sound.add is not a function
 
It makes me think I need to call some function I can't find, like
this.sound = this.sound.clear();
this.sound = this.sound.unload();
or something so that it will again allow me to pass in a sound key.
 
thanks
 
 
 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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