我有一個物體在屏幕上移動,一旦它到達邊緣,它就會改變方向並播放聲音,這一切都可以正常工作,除非播放聲音時我凍結了大約半秒鐘有沒有什麼方法可以使聲音和物體運動順利進行?在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字符,這些字符很容易混淆。 –