Iphone 弹跳球程序希望球重新出现在顶部并再次落下
现在在我的程序中,球在Y轴上上上下反弹。我想要的是球只能向下移动。当它到达屏幕底部时,我希望它在顶部重新出现,然后再次向下开始。不断地从上到下移动Iphone 弹跳球程序希望球重新出现在顶部并再次落下,iphone,Iphone,现在在我的程序中,球在Y轴上上上下反弹。我想要的是球只能向下移动。当它到达屏幕底部时,我希望它在顶部重新出现,然后再次向下开始。不断地从上到下移动 @implementation BounceViewController @synthesize ball; -(void) bounce{ ball.center = CGPointMake(ball.center.x+position.x, ball.center.y+position.y); { if(ball.c
@implementation BounceViewController
@synthesize ball;
-(void) bounce{
ball.center = CGPointMake(ball.center.x+position.x, ball.center.y+position.y); {
if(ball.center.y>450 ||ball.center.y <0)
position.y = -position.y; }
}
- (void)viewDidLoad {
position = CGPointMake(0, 10);
[NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(bounce) userInfo:nil repeats:YES];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setBall:nil];
[super viewDidUnload];
}
@end
在反弹方法中,替换线
if(ball.center.y>450 ||ball.center.y <0)
position.y = -position.y;
与
if(ball.center.y>450 ||ball.center.y <0)
ball.center = CGPointMake(ball.center.x+position.x, position.y);