salocinx salocinx - 2 months ago 174
iOS Question

Sprite Kit: Why does playing sound return error?

I upgraded my Sprite Kit game to X-Code 8.0 and Swift 3 yesterday. Deployment target is currently set to iOS 9.3.

I play sound effects the following way:

self.run(SKAction.playSoundFileNamed("click.caf", waitForCompletion: false))


The sound effect is not played correctly (only about the half of the samples) and I get the following error (since upgrade to X-Code 8.0 and Swift 3):

SKAction: Error playing sound resource


Any ideas ?

Answer

The problem disappeared when I removed this preload code. Do you have something similar? But now I get a short delay the first time a sound is played. Don't know how I shall handle that.

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Preload sounds
  [SKAction playSoundFileNamed:@"coinBlip.wav" waitForCompletion:NO];
  [SKAction playSoundFileNamed:@"bonus.wav" waitForCompletion:NO];
  :