Jump to content

changing from one sound to another sound seems broken


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');
and then after a user does something a little latter
this.sound = this.sound.add('staraudio');
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.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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