Jump to content

sound signal onStop


thehui87
 Share

Recommended Posts

Hi, could anyone help me out on this one,

I am unable to go back to  my previous state (scene1), once the audio clip has been played.

 

I get an error message: undefined this.game.state

 

the audio is one long clip of all the game sounds, so i used 'addMarker'.

Sc2 = function(game){var sfx;var array1;var array2;var sprite1;};Sc2.prototype = {create: function(){sfx= this.add.audio('myaudio');sfx.addMarker('endClip', 13, 3);//CODEsprite1 = this.add.sprite(300,222,'atlas');sprite1.frameName = "eagle.png";sprite1.inputEnabled = true;sprite1.input.enableDrag(false, true);sprite1.events.onInputDown(checkInput, this);//},update: function(){},};function checkInput(){//CODE    checkCompletion();}function checkCompletion(){var counter = 0;   for(var i = 0; i<5; i++ ){        if(array1[i] == array2[i])        {             counter++;         }   }    if(counter == 5)    {          var endClipAudio =  sfx.play('endClip');          endClipAudio.onStop.addOnce(backtoScene1,this);    } ]function backtoScene1(){    this.game.state.add('Scene1', Sc1);    this.game.state.start('Scene1');}

Thanks...

 

Link to comment
Share on other sites

  • 1 year later...

2 years later, same issue. I added my sounds once after preload, and re-use them across the game. I assumed this would be faster/optimized, but it broke here (when attempting to add an onStop callback). Only when I attempted to use it twice tho (on the second consecutive play through of the Game state). Version: `Phaser 2.6.2`

//broken sound
//Preload state
onLoadComplete() {

    this.game.audio = {
      biteScary: this.game.add.audio('bite_scary')
    };
}

//game state
this.game.audio.biteScary.onStop.add(function() {
      this.game.state.start('Gameover', true, false);
    }, this);
    this.game.audio.biteScary.play();
//fixed sound - game state
var bite = this.game.add.audio('bite_scary');
    bite.onStop.add(function() {
      this.game.state.start('Gameover', true, false);
    }, this);
    bite.play();

 

 

Edit: Rich corrects the problem here https://github.com/photonstorm/phaser/issues/2748#issuecomment-249970148

Link to comment
Share on other sites

  • 2 years later...
 Share

  • Recently Browsing   0 members

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