0
我正在用Sprit Kit构建游戏,我在didMoveToView方法中使用了AVAudioPlayer的连续循环声音。但是我还使用SystemSoundID使用了其他四种声音,这些声音是在didMoveToView方法之外创建的。问题是当我玩游戏时,使用AVAudioPlayer播放声音似乎淹没了我使用systemSound的所有其他声音。我可以使用AVAudio来处理所有听起来不错的声音,但它也会让我的游戏减慢一点。只是想知道是否有替代或修复?忘了提及,它只是似乎是一个问题,当我插入耳机,但它播放时没有工作正常。播放AVAudioPlayer和SystemSoundID
这里是我的代码:
- (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);