thehui87 Posted October 5, 2014 Share Posted October 5, 2014 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 More sharing options...
JTronLabs Posted September 8, 2016 Share Posted September 8, 2016 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 More sharing options...
Shrinidhi Posted June 26, 2019 Share Posted June 26, 2019 hi, how can i create a event onStop for a media file. Link to comment Share on other sites More sharing options...
Recommended Posts