I’d like to create random images falling from the top of the screen, down to the bottom where they disappear. So far, I’ve been able to make 1 image fall down, at a fixed spawn point (center), but I’m unsure how to generate many more that spawn at random places on the top (somewhat like a snowfall or rainfall effect).
This is what I have so far:
-(void) viewDidLoad {
moveObjectTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(moveObject) userInfo:nil repeats:YES]; }
-(void) moveObject { // + means down and 5 is SPEED
bird.center = CGPointMake(bird.center.x, bird.center.y +5); }
Say suppose you have 10 images in an array, then to select any 10 images at random you would do;
int randomIndex rand()/RAND_MAX * 10 + 1;
Then in some method, you could animate it as;
Your NSTimer should trigger this method and then this would select the random image out of your images, here I suppose 10 images that you have in an array. Then this would animate the images from outside the top/right corner to the bottom left corner at the specified time interval as specified with NSTimer.