我试图在用户触摸按钮时进行随机声音播放。到目前为止,这是我的代码:
-(void) playEffect {
NSArray *array = [NSArray arrayWithObjects:@"1.mp3", "2.mp3", "3.mp3", nil];
int index;
index = random() % array.count;
sound *theSound = [array objectAtIndex:index];
[theSound play];
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//Blah, blah, blah
//PLAY RANDOM SOUND
[self playEffect];
}
提前感谢您的时间和帮助。
答案 0 :(得分:1)
您可以使用CocosDenshion。像Smth一样
[[SimpleAudioEngine sharedEngine] playEffect: pathToYourSoundFile];