2011-11-19 85 views
0

我能夠在線性路徑中進行動畫製作。我如何讓他們編程以隨機路徑移動?我閱讀開發人員的「移動我」示例代碼,但它不夠清楚。那裏有其他的動畫教程嗎?iPhone:爲動畫生成隨機路徑

//Loading the array with images 
     NSArray *myImages = [NSArray arrayWithObjects: 
          [UIImage imageNamed:@"enemyball.png"], 
          [UIImage imageNamed:@"playerball.png"] 
          , nil]; 

     //animation of images 
     UIImageView *animatedView =[[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 50.0, 50.0)]; 

     animatedView.animationImages = myImages; 
     animatedView.animationDuration = 0.25; // seconds 
     animatedView.animationRepeatCount = 0; //0 loops for ever/noted 
     [animatedView startAnimating]; 
     [self addSubview:animatedView]; 


     //animation movement 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:4]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 

     [UIView setAnimationRepeatCount:INFINITY]; 
     [UIView setAnimationRepeatAutoreverses:YES]; 
     [UIView setAnimationBeginsFromCurrentState:YES]; 

     CGAffineTransform transform = CGAffineTransformMakeTranslation(100, 0); 
     animatedView.transform = transform; 

     [UIView commitAnimations]; 
+0

請將代碼粘貼在這裏...有很多方法可以完成動畫..不清楚您使用的是哪種方法 –

+0

我已經添加了代碼。我正在使用塊動畫。 –

回答

0

我不知道你是在問動畫技術還是你只是在問隨機散步。如果後者,wiki page是一個好的開始。