Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Make 2 balls move at once

I have been stuck with this bug for a long time. I need to make 2 balls move at once. When I add the second ball, both of the balls get messed up. Here is the code in my .m file.


-(void) onTimer {


ball.center = CGPointMake(ball.center.x+pos.x,ball.center.y+pos.y);


if(ball.center.x > 295 || ball.center.x < 10)

pos.x = -pos.x;

if(ball.center.y > 435 || ball.center.y < 35)

pos.y = -pos.y;

ball2.center = CGPointMake(ball2.center.x+pos.x,ball2.center.y+pos.y);


if(ball2.center.x > 295 || ball2.center.x < 10)

pos.x = -pos.x;

if(ball2.center.y > 435 || ball2.center.y < 35)

pos.y = -pos.y;

[selfcollision];



}

- (void)viewDidLoad

{


[[NSTimerscheduledTimerWithTimeInterval:0.04target:selfselector:@selector(onTimer) userInfo:nilrepeats:YES] retain];



[superviewDidLoad];


}


Any help would be great.

xcode-OTHER, OS X Mountain Lion (10.8.4)

Posted on Sep 22, 2013 6:41 PM

Reply
2 replies

Make 2 balls move at once

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.