移动时动画多帧的正确方法

时间:2013-03-26 00:50:24

标签: ios objective-c animation

我想知道这是在游戏角色从a点移动到b点时动画游戏角色的正确方法,同时显示模拟人物移动的不同运动图像。

以下是我所做的persudo代码:

    [UIView animateWithDuration:dMAN_MOVEMENT_SPEED/3 animations:^{
            //Set Target Image
            //Set target position
    }completion:^(BOOL finished){
        //2nd to 3rd Frame
        [UIView animateWithDuration:dMAN_MOVEMENT_SPEED/3 animations:^{
            //Set Target Image
            //Set target position
        }completion:^(BOOL finished){
            //3rd to final Frame
            [UIView animateWithDuration:dMAN_MOVEMENT_SPEED/3 animations:^{
                //Set Target Image
                //Set target position
            }completion:^(BOOL finished){
                //do nothing
            }];
        }];
    }];

这是正确的方法吗?我是这样做的,因为我可以控制每个帧和每个帧的持续时间。

1 个答案:

答案 0 :(得分:3)

似乎可能有更好的方法。如果您没有太多图片,我可能只建议使用animationImages的{​​{1}}属性然后UIImageView

startAnimating

如果您担心将所有内容加载到内存中,您还可以使用NSArray *images = @[[UIImage imageNamed:@"0.jpg"], [UIImage imageNamed:@"1.jpg"], [UIImage imageNamed:@"2.jpg"], [UIImage imageNamed:@"3.jpg"], [UIImage imageNamed:@"4.jpg"], [UIImage imageNamed:@"5.jpg"], [UIImage imageNamed:@"6.jpg"], [UIImage imageNamed:@"7.jpg"]]; self.imageView.image = images[0]; self.imageView.animationImages = images; self.imageView.animationDuration = kAnimationDuration; self.imageView.animationRepeatCount = 1; [self.imageView startAnimating]; [UIView animateWithDuration:kAnimationDuration animations:^{ self.imageView.center = ... // set this to whatever you want }]; 加载适当的图像,如下所示:

CADisplayLink