I am trying to implement an on/off button in Sprite Kit for the music/sound effects. Here is the code to set up the buttons:
-(void)setUpSoundIcon{
if (soundOrNoSound == YES) {
soundIcon = [SKSpriteNode spriteNodeWithImageNamed:[self imageNamed:@"sound"]];
sound = 2;
}else if (soundOrNoSound == NO) {
soundIcon = [SKSpriteNode spriteNodeWithImageNamed:[self imageNamed:@"nosound"]];
sound = 1;
}
soundIcon.name = @"Sound";
if (screenWidth == 1024 && screenHeight == 768) {
soundIcon.position = CGPointMake(screenWidth - 50, 50);
}else if(screenHeight == 320){
soundIcon.position = CGPointMake(screenWidth - 30, 30);
}
[soundIcon setZPosition:2000];
[self addChild:soundIcon];
}
Then in the touchesBegan method I have the sound icon image change to represent the music on or off. So, my problem is that I have the background music playing correctly, I just need a way to see if the user pressed the sound icon to be off, and then making sure the music and sound effects do not play unless the user pressed the sound icon on. I need a way to do it so that it works between multiple classes too. Thank you!