【发布时间】:2012-09-13 18:39:29
【问题描述】:
当一帧撞到另一帧时,它会播放声音,所以我在 did 加载器中使用此代码来加载声音
我使用框架
#import <AVFoundation/AVFoundation.h>
- (void)viewDidLoad
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"ballbounce" ofType:@"mp3"];
theaudio1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error: NULL];
然后用它来播放声音
[audio1 play];
但有时声音不播放,声音片段只有 0.7 秒长,只是发出简单的噪音。
喜欢
enemy.center = CGPointMake(enemy.center.x+pos.x,enemy.center.y+pos.y);
if (enemy.center.x > 308 || enemy.center.x < 10)
{
[theaudio1 play];
pos.x = -pos.x;
}
if (enemy.center.y > 400 || enemy.center.y < 100)
{
[theaudio1 play];
pos.y = -pos.y ;
}
声音有时会快速连续播放,有时声音不播放是否有更好的方法可以编写此代码?
【问题讨论】:
标签: iphone objective-c c xcode audio