Question

Im trying to remove a repeated playing MP3 when two nodes collide.

SKAction* gameBeat = [SKAction playSoundFileNamed:@"gameBeat.mp3" waitForCompletion:YES];
SKAction* gameBeatLoop = [SKAction repeatActionForever: gameBeat];
[self runAction:gameBeatLoop withKey:@"gameBeatzz"];

then later down in my code where I have collision working I put :

[self removeActionForKey:@"gameBeatzz"];

but it waits until the MP3 is done playing, which I do not want.

If I change waitForCompletion to NO, the APP just gets messed up and won't do anything.

How would I go about removing the Mp3 instantly instead of waiting for the MP3 file to finish

Était-ce utile?

La solution

It is normal that if you set your waitForCompletion bool to NO the app doesn't do anything. It is because the action is considered to have completed immediately.

The action for playSoundFileNamed is not reversible and makes a final change to the scene when removed, it continues to the end...
Some SKAction are completely removed from node when you perform the removeAction method, but some continues to work.

The playSoundFileNamed was created to perform short sounds and not a background sound.

I recommend to use the AVAudioPlayer that allows you bigger control on music.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top