我正在用Sprit Kit构建游戏,我在didMoveToView方法中使用AVAudioPlayer连续循环播放声音。但我也使用SystemSoundID使用其他四种声音,这些声音是在didMoveToView方法之外创建的。问题是,当我玩我的游戏时,使用AVAudioPlayer播放的声音似乎淹没了我使用systemSound的所有其他声音。我可以将AVAudio用于所有似乎工作正常的声音,但它也会减慢我的游戏速度。只是想知道是否有替代或修复此问题?忘了提一下,当我插入耳机时它似乎只是一个问题,但在没有播放时工作正常。
这是我的代码:
- (void)didMoveToView:(SKView *)view
NSURL *playSound = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"jungleSound" ofType:@"wav"]];
NSError *error;
player = [[AVAudioPlayer alloc]initWithContentsOfURL:playSound error:&error];
[player play];
player.numberOfLoops = -1; //Continuous play//
在方法之外
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Jump2" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound(soundID);
NSString *soundPath2 = [[NSBundle mainBundle] pathForResource:@"squish" ofType:@"wav"];
SystemSoundID soundID2;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath2], &soundID2);
AudioServicesPlaySystemSound(soundID2);
NSString *soundPath3 = [[NSBundle mainBundle] pathForResource:@"Powerup3" ofType:@"wav"];
SystemSoundID soundID3;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath3], & soundID3);
AudioServicesPlaySystemSound(soundID3);
答案 0 :(得分:0)
在铃声中调高音量并在设置下发出警报解决了这个问题。