swift – 如何为SKShapeNode的不透明度设置动画?

我正在我的游戏的说明屏幕上工作,并希望向用户显示他们应该点击屏幕的某个区域.

所以我想在哪里展示动画

1)手指伸缩进出屏幕,然后 – 工作正常 –

2)改变不透明度的矩形(显示点击那里)然后 – 需要帮助 –

3)文本闪烁,说“点击这里” – 需要帮助 –

对于1),我有这个(工作正常):

finger = SKSpriteNode(texture: fingerTxt)
    finger.position = CGPoint(x: 330, y: 450)
    finger.zPosition = 10
    InstHolderNode.addChild(finger)

    let fingerTapScaleDown = SKAction.scale(by: 0.6, duration: 0.7)
    let fingerTapScaleUp = SKAction.scale(by: 1.6, duration: 0.7)
    let fingerScalingSequence = SKAction.sequence([fingerTapScaleDown,fingerTapScaleUp])

    let fingerTapScaleForever = SKAction.repeatForever(fingerScalingSequence)
    finger.run(fingerTapScaleForever)

对于2),我有:

var rect = SKShapeNode(rectOf: CGSize(width: 150.0, height: frame.height * 2))
    rect.position = CGPoint(x: 300, y: 100)
    rect.fillColor = SKColor.brown
    rect.alpha = 0.5
    InstHolderNode.addChild(rect)

题 :

如何同步1)和2)这样1)完成后(手指敲击动画完成),rect.alpha值改为0.1然后改回0.5然后1)发生然后rect.alpha是更改为连续更改为0.1(循环).

非常感谢!!

试试这个:

var fadeOut = SKAction.fadeAlpha(to: 0.1, duration: 0.5)
    var fadeIn = SKAction.fadeAlpha(to: 0.5, duration: 0.5)

    rect.run(SKAction.repeatForever(SKAction.sequence([fingerScalingSequence, fadeOut, fadeIn])))

根据您的喜好调整持续时间

翻译自:https://stackoverflow.com/questions/39775608/how-to-animate-the-opacity-of-a-skshapenode