2012-03-28 9 views
1

私のプログラムでは、ボールはY軸上を上下にバウンスします。私が望むのは、ボールが下方向にのみ動くことです。それが画面の一番下に来ると、画面の一番上に再表示され、再び開始されます。上から下へ連続的に移動します。あなたのバウンス方法でボールが跳ね返っているプログラムボールが一番上に現れて再び降りてくるようになります

@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 

答えて

0

if(ball.center.y>450 ||ball.center.y <0) 
     ball.center = CGPointMake(ball.center.x+position.x, position.y); 
でライン

if(ball.center.y>450 ||ball.center.y <0) 
      position.y = -position.y; 

を交換

関連する問題