Sprite Kit中的弹跳节点

时间:2015-11-05 00:41:53

标签: iphone sprite-kit

我通过改变它的位置来移动节点。我想在移动时添加类似于此效果:link

1 个答案:

答案 0 :(得分:1)

实现这一目标的最简单方法是使用SKAction 这个例子只是向上和向下移动,但是组合向上/向左/向右/向下移动它会产生你的角色/节点跳跃的效果。

您可以调整数字以使其更逼真

moveDuration - 你的角色/节点移动1个瓦片所需的时间

runAction(SKAction.sequence([
        SKAction.moveByX(0, y: character.frame.size.height / 2, duration: moveDuration / 2),  
        SKAction.moveByX(0, y: -character.frame.size.height / 2, duration: moveDuration / 2),
    ]))

如果你想要更真实,试试这个:

runAction(SKAction.sequence([
        SKAction.moveByX(0, y: character.frame.size.height / 2 * 0.5, duration: moveDuration / 6),
        SKAction.moveByX(0, y: character.frame.size.height / 2 * 0.35, duration: moveDuration / 6),
        SKAction.moveByX(0, y: character.frame.size.height / 2 * 0.15, duration: moveDuration / 6),  
        SKAction.moveByX(0, y: -character.frame.size.height / 2 * 0.15, duration: moveDuration / 6),
        SKAction.moveByX(0, y: -character.frame.size.height / 2 * 0.35, duration: moveDuration / 6),
        SKAction.moveByX(0, y: -character.frame.size.height / 2 * 0.5, duration: moveDuration / 6),
    ]))