我有一个物体在屏幕上移动,一旦它到达边缘它就会改变方向并播放声音这一切都很好,除了当它播放声音时我冻结了大约半秒钟有什么方法可以让它顺利运行声音和物体的运动?
-(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];
}