So basically I have a sprite that bounces around the screen, and when it reaches a certain Y coordinate I have it reverse direction. but sometimes, and only maybe once out of a hudred, it seems to get stuck and tries reversing its Y direction over and over again. Any idea why this may be? thanks!
Called in init method:
[self unschedule:@selector(move)];
move method:
-(void)move{
CCNode *ball = [self getChildByTag:kTagBall];
int x = 5;
int y = 5;
//if Ball hits boundries, reverse directions.
if (ball.position.x > 480 || ball.position.x < 0) {
x = -x;
}
if (ball.position.y >= 240 || ball.position.y < 0) {
y = -y;
}
ball.position = ccp(ball.position.x + x, ball.position.y + y);
}