0

每当用户触摸按钮时,我都会尝试随机播放声音。到目前为止,这是我的代码:

-(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];  
}

提前感谢您的时间和帮助。

4

1 回答 1

1

您可以为此使用 CocosDenshion。喜欢

[[SimpleAudioEngine sharedEngine] playEffect: pathToYourSoundFile];
于 2012-05-16T10:17:51.810 回答