每次我点击游戏中的屏幕时我都在试着播放声音.
基本上,每次我的角色跳跃,我都不会有一点声音。不幸的是,它似乎只在循环(来自上一次跳转)已经完成前一次会话的播放时才播放.意思是我每次触摸屏幕都不会受到声音的影响.
利用这一框架:
#import <AVFoundation/AVFoundation.h>我就是这样加载我的文件的:
-(void)LoadMusic{
NSString *jumpSound = [[NSBundle mainBundle] pathForResource:@"Burst" ofType:@"mp3"];
jumpAffect = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:jumpSound] error:NULL];
jumpAffect.delegate = self;
}在viewDidLoad中调用它:
- (void)viewDidLoad{
[self LoadMusic];
...
[super viewDidLoad];
}这就是我想让它播放的时候(每次我触摸屏幕(让角色跳转):
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event{
[jumpAffect play];
jump = 16;
}有什么东西我忘了让循环在对方身上播放吗?或者我可以停止循环,并重新启动它,如果它还在播放时,发生下一个触摸?
发布于 2014-10-09 19:56:13
试着做这样的事情:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self playJumpSound];
}
- (void)playJumpSound {
AVAudioPlayer *jumpEffect = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:jumpSound] error:NULL];
[jumpEffect play];
}如果您发现加载您的声音太慢,加载在前面的一小撮,然后再使用播放器。
https://stackoverflow.com/questions/26286822
复制相似问题