- Set up a int in the .h file, maybe
int balloonMovement
- Link all your balloon images to your .h in between your curly brackets as IBOutlets
i.e. IBOutlet UIImageView *balloon1;
IBOutlet UIImageView *balloon2;
- Set up another
int randomPosition
and use a random number generator to set positions of balloons on the screen, maybe when user clicks start, or something happens.
You could have this in the viewDidLoad:
RandomPosition = arc4random()%248; //the number of possibilities
RandomPosition = RandomPosition + 36; //the new position
balloon1.center = CGPointMake(RandomPosition, RandomPosition); //make position
This makes them appear randomly on the screen.
Then, to have them float upward, set up int upMovement;
and an NSTimer *movement;
, and have it set so every so often, they move upward.
Use the following code to do so:
movement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moving) userInfo:nil repeats:YES];
This says, every 0.05 seconds, we want to activate the movement.
Then create a method for balloonMovement -- -(void)balloonMovement;
in the .h
And fill out its info in the .m -->
-(void)balloonMovement {
balloon1.center = CGPointMake(balloon1.center.x, balloon1.center.y + upMovement);
}
And another one for the actual moving of the balloon, and set up the conditions that you want them to float upwards, i.e. user cuts string?
-(void)balloonMoving {
upMovement = upMovement + 0.1 //this will make it gradually faster
if (//user cuts string code) {
[self balloonMovement];
}
}
This should work. Obviously it's very simple. You will have to customise it. But this should give you the basics. Hope it helped.
One more thing**
To make them change positions as they go up the screen, you'll have to set up a int sideMovement, and add it the same way you did upMovement. But I'll leave that to you to figure out.