문제

I am getting this error after about 80 shots of a laser using a controlled Timer Interval so it fires every 0.2 seconds.

* Terminating app due to uncaught exception 'Failed to Load Resource', reason: 'Resource squish.mp3 can not be loaded' * First throw call stack:

Here is the code I use to play the sound and create the laser. squish.mp3 is an audio file that is played when an object is destroyed. Can anyone help? Is SKAction not very good for playing sound?

SKAction *sound = [SKAction playSoundFileNamed:@"lazer.mp3" waitForCompletion:NO];
[self runAction:sound];
[self removeActionForKey:@"sound"];
SKSpriteNode *laser = [SKSpriteNode spriteNodeWithImageNamed:@"fire"];
도움이 되었습니까?

해결책 2

Not sure why I didn't try this but I just replaced the sound file and it seems to have cured it. However, if there was an error with the audio file why did it play around 200 times before crashing.

다른 팁

I was running into the same problem and I think I have a solution, though I'm not sure. I haven't seen the same crash in a while though.

Make a single SKAction that represents playing the laser sound, and reuse that object.

I think playSoundFileNamed: is supposed to be smart about not re-loading the audio file from the file system every time it's used. But the crash indicates that it does get reloaded, at least occasionally. Keeping an SKAction around to reuse means that the audio file is only loaded once.

I would use a more Apple-compatible format, like AAC (.m4a) for the sound file. Apple doesn't take too kindly with .mp3s. However, I think the file can be a Microsoft .wav file

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top