Hi,
In my current project i have a sound source that is set to loop and i want to start and stop playing when certain events are fired. What i noticed is that if i tab out of the game window a moment before the event is fired i will not receive it when i tab back in and the audio source will stuck on a loop and when i place a breakpoint in the developer tools this all works normally .
Here are some code snippets to help explain, this code controls a slot machine:
1)every time a reel stops an event is fired.
ReelScript.prototype.ReelBounce = function(stopPoint)
{
this.symbolsCreatedAfterTween = 0;
setTimeout( () =>
{
this.isSpinning = false;
this.spinSpeed = 0;
console.log(this.symbolsCreatedAfterTween);
**this.app.fire(ReelScript.Events.SPIN_ENDED);**
},this.reelStopTime * 1000);
};
2)Once all reels have stopped a second event is fired
ReelsManager.prototype.ReelStopped = function()
{
this.stoppedReels++;
if(this.stoppedReels == this.reelsArray.length)
{
**this.app.fire(ReelsManager.Events.SPIN_ENDED);**
console.log("all reels stopped");
for(var i = 0; i<this.reelsArray.length; i++)
{
this.reelsArray[i].script.reelScript.isAllowedToSpin = true;
}
this.stoppedReels = 0;
}
};
3)this last event finally calls the function that stops the sound
SlotMachineSoundManager.prototype.initialize = function() {
this.app.on(ReelsManager.Events.SPIN_STARTED,this.playSpinMusic,this);
**this.app.on(ReelsManager.Events.SPIN_ENDED,this.stopSpinMusic,this);**
};
SlotMachineSoundManager.prototype.stopSpinMusic = function(){
this.SpinMusicSource.sound.stop("SpinMusic");
};
The stopSpinMusic function is not called if i tab out of the screen when the last reels is spinning. If i stay on the window or tab out early there is no issue. Really confused here.