Judging by this piece of code, it looks like you have one controller that “owns” ten balls, and you want the balls to bounce according to a set of rules that are unique to each ball. A more object oriented approach would be:
@interface JumpBallClass
{
CGPoint center;
CGPoint speed;
CGPoint lowerLimit;
CGPoint upperLimit;
}
@property (assign) CGPoint lowerLimit;
@property (assign) CGPoint upperLimit;
- (void)update;
@end
@implementation JumpBallClass
- (void)update
{
center.x += speed.x;
center.y += speed.y;
if (center.x > upperLimit.x || center.x < lowerLimit.x)
{ speed.x = -speed.x; }
if (center.y > upperLimit.y || center.y < lowerLimit.y)
{ speed.y = -speed.y; }
}
@end
This setting allows you to configure all the balls once, setting their upper and lower limits:
[jumpBall1 setUpperLimit:CGPointMake(60, 211)];
[jumpBall1 setLowerLimit:CGPointMake(0, 82)];
...
And then just calling updateon each ball in the timer method:
- (void) jumpOnTimer {
[jumpBall1 update];
[jumpBall2 update];
...
}
This can be simplified by saving all the balls in NSArray:
NSArray * balls = [NSArray arrayWithObjects:jumpBall1, jumpBall2, ..., nil];
And then calling makeObjectsPerformSelector:
[balls makeObjectsPerformSelector:@selector(update)]