I currently have two scenes in my game
When entering scene one music plays. When the game is over and the user enters scene two, the music stops. When opting to retry the game, the music plays again.
I attempted to code the music to play continuously
[self runAction:[SKAction playSoundFileNamed:@"YourFileName.extension" waitForCompletion:NO]];
This works fantastically in the sense that when the game is over, the music is still playing rather than being cut off. However, when opting to retry and entering scene one again, the music continues but is also triggered again, resulting in a duplication. This can keep happening.
Is there a way to detect if the audio is already playing so that it won't continue to get triggered every time I enter scene one?
Create a bool initialized to NO:
bool isMusicPlaying;
When you start the music, set the bool to YES and make sure music does not get started if already playing :
if(isMusicPlaying == NO)
{
[self runAction:[SKAction playSoundFileNamed:@"YourFileName.extension" waitForCompletion:NO]];
isMusicPlaying = YES;
}