iPhone:为动画生成随机路径

时间:2011-11-19 04:33:29

标签: objective-c ios animation sdk

我可以在线性路径中播放动画。如何让它们编程以随机路径移动?我读过开发人员的“移动我”示例代码,但不够清楚。是否还有其他动画,如这些动画?

//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];

1 个答案:

答案 0 :(得分:0)

我不知道你是否在询问动画技术,或者你只是在询问随机游走。如果是后者,wiki page是一个好的开始。