我有一个物体在屏幕上移动,一旦它到达边缘,它就会改变方向并播放声音,这一切都可以正常工作,除非播放声音时我冻结了大约半秒钟有没有什么方法可以使声音和物体运动顺利进行?在iOS平稳地播放声音
-(void)viewDidLoader
{
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"ballbounce" ofType:@"mp3"];
ballbounce = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error: NULL];
[ballbounce prepareToPlay];
}
-(void) ballcollition
{
[self ballplaysound]
enemy.center = CGPointMake(enemy.center.x+pos.x,enemy.center.y+pos.y);
if (enemy.center.x > 328 || enemy.center.x < 0)
{
pos.x = -pos.x;
}
}
-(void)ballplaysound
{
if (enemy.center.x > 328 || enemy.center.x < 0 ||enemy.center.y < 0||enemy.center.y < 300)
[ballbounce play];
}
嘿,这工作后很多的调整,但绝对少了头 –
我更新了ARC。请注意,如果您复制粘贴原始代码,那么会有些奇怪的情况发生,即引用其他一些非有效的LLFM字符,这些字符很容易混淆。 –