将动画从艺术家转换为代码

时间:2017-03-13 15:51:59

标签: ios animation mobile cocos2d-iphone uikit

在我们的开发过程中,我们遇到了很多情况,其中艺术家/设计会模拟动画,开发人员将负责转换为代码 - 无论是UIView动画还是像Cocos2D这样的游戏引擎中的CCActions。

问题是我们没有很好的方法将艺术家/设计师提供的动画(通常以Flash / After Effects或类似工具的形式)直接转换为代码。开发人员必须花费大量时间来确定精确的动画参数,并最终得到如下代码:

CAAnimationGroup *(^groupedAnimation)(CGMutablePathRef curvedPath, NSTimeInterval delay) = ^(CGMutablePathRef curvedPath, NSTimeInterval delay) {

    CGFloat moveTime = 1.6;

    CABasicAnimation *scaling = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaling.fromValue = @1.;
    scaling.toValue = @0.05;
    scaling.beginTime = delay;
    scaling.duration = moveTime;
    scaling.removedOnCompletion = NO;
    scaling.fillMode = kCAFillModeForwards;
    scaling.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacity.fromValue = @1.;
    opacity.toValue = @0.1;
    opacity.beginTime = delay + moveTime-0.6;
    opacity.duration = 0.5;
    opacity.removedOnCompletion = NO;
    opacity.fillMode = kCAFillModeForwards;
    opacity.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

    CAKeyframeAnimation *path = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    path.beginTime = delay;
    path.duration = moveTime;
    path.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    path.path = curvedPath;
    path.calculationMode = kCAAnimationPaced;
    path.removedOnCompletion = NO;
    path.fillMode = kCAFillModeForwards;

    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[scaling, opacity, path];
    group.beginTime = 0;
    group.duration = moveTime+delay;
    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;

    return group;
};

在代码中找出这些动画的参数是一个非常手动的过程,需要大量关注动画模拟并迭代地缩小看起来很好的值。通常非常耗时且乏味。

有更好的流程吗?这是什么行业标准?

由于

1 个答案:

答案 0 :(得分:0)

看一下SpriteKit场景编辑器,

在XCode->创建新项目 - >游戏 - >游戏技术= SpriteKit

然后在项目导航器

中单击扩展名为.sks的文件,打开场景编辑器

您可以在没有单行代码的情况下试验动画并实现上述目标