Created
November 6, 2012 21:27
-
-
Save nathanclark/4027691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example of how to trigger a random timer with a floor of 1 and a ceiling of 4; | |
-(void)random{ | |
int randNum = rand() % (4 - 1) + 1; //create the random number. | |
NSLog(@"[DEBUG] random triggered %i", randNum); | |
// Choosing a random sound effect | |
NSString *filename = [NSString stringWithFormat:@"soundEffect%i",randNum]; | |
NSString *filePath = [[NSBundle mainBundle] pathForResource:filename ofType:@"caf"]; | |
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] | |
initWithContentsOfURL:[NSURL fileURLWithPath:filePath] | |
error:&error]; | |
if (error) | |
NSLog(@"Error: %@", | |
[error localizedDescription]); | |
else | |
[audioPlayer play]; | |
[self performSelector:@selector(random) withObject:self afterDelay:randNum]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment