iOS 7 Sprite Kit适用于动画的速度变化

时间:2014-02-06 22:29:54

标签: ios objective-c ios7 sprite-kit

我有runAction动画SKSpriteNode。我让节点在repeatActionForever中上下移动。我希望节点在节点向上移动时减速,并在节点向下移动时加速。

[node runAction:[SKAction repeatActionForever:
                       [SKAction sequence:@
                        [[SKAction speedTo:0.1 duration:0.5],
                         [SKAction moveToY:2 * node.size.height / 3 duration:0.5],
                         [SKAction speedTo:1 duration:0.5],
                         [SKAction moveToY:node.size.height / 2 duration:0.5],
                         [SKAction moveToY:node.size.height duration:1],
                         [SKAction moveToY:node.size.height / 2 duration:1]]]]];

当我添加行[SKAction speedTo:0 duration:0.5]时,其余的代码在0.5秒后以0的速度运行,即使我添加了第二个speedTo动作,这会将速度提高到1。

问题:如何在节点移动时更改节点的速度,而不是每个方向都停滞不前。

提前致谢。

1 个答案:

答案 0 :(得分:6)

查找各种类型的SKActionTimingMode并根据需要应用这些类型。这样就不需要[SKAction speedTo:0.1 duration:0.5]

https://developer.apple.com/library/mac/documentation/SpriteKit/Reference/SKAction_Ref/Reference/Reference.html#//apple_ref/c/tdef/SKActionTimingMode

您可以将SKActionTimingEaseOut用于使节点向上移动的操作,并使用SKActionTimingEaseIn用于使节点向下移动的操作。

SKAction *actionMoveUp = [SKAction moveToY:2 * node.size.height / 3 duration:0.5];
actionMoveUp.timingMode = SKActionTimingEaseOut;

SKAction *actionMoveDown = [SKAction moveToY:node.size.height / 2 duration:0.5];
actionMoveDown.timingMode = SKActionTimingEaseIn;

SKAction *actionMoveUpHalf = [SKAction moveToY:node.size.height duration:1];
actionMoveUp.timingMode = SKActionTimingEaseOut;

[node runAction:[SKAction repeatActionForever:
                       [SKAction sequence:@
                        [actionMoveUp,
                         actionMoveDown,
                         actionMoveUpHalf,
                         actionMoveDown]]]];