简体   繁体   中英

SpriteKit: Getting Audio to stop playing

I have code in my Objective-C SpriteKit game to loop a menu theme, but I don't quite know how to get it to stop looping. Here's what I'm using:

[self runAction:[SKAction sequence:[NSArray arrayWithObjects:[SKAction playSoundFileNamed:@"Main Menu Warmup 1.m4a" waitForCompletion:YES], [SKAction runBlock:^{
    [self manageMusic];
}], nil]]];

That loops the music just fine, but if I try to call [self removeAllActions] to stop the music later, then the music continues playing. Any ideas on how to fix this?

This issue has been addressed in the below url. how to pause the sound when use SpriteKit

It is mentioned as follows, there is the basis of what you can do using AVAudio. I will use background music in this example but it can be done any way. You could put this in a subclass of SKSpriteNode to have a custom sound that can be pause by itself or others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM