1

我想要的效果就像水面上的雨滴,波浪从中心点向外辐射。

我创建了一个圆形:

    let initialRadius = 4.0
    let myPath: CGMutablePathRef = CGPathCreateMutable()
    CGPathAddArc(myPath, nil, 0, 0, initialRadius, 0, M_PI * 2, true)

    let myCircle = SKShapeNode()
    myCircle.path = myPath
    myCircle.position = CGPoint(x: xPos, y: yPos)
    myCircle.lineWidth = 0.5
    myCircle.antialiased = false
    myCircle.fillColor = SKColor.orangeColor() // background is orange
    myCircle.strokeColor = SKColor.whiteColor()
    myCircle.physicsBody = SKPhysicsBody(edgeLoopFromPath: myPath)

然后我让精灵展开,然后淡出:

    let duration: NSTimeInterval = 1.7
    let fade = SKAction.fadeOutWithDuration(duration)
    let scale = SKAction.scaleTo(9.0, duration: duration)
    fade.timingMode = .EaseOut
    scale.timingMode = .EaseOut
    myCircle.runAction(fade)
    myCircle.runAction(scale)

这很接近,但是当圆圈的大小正确扩大时,lineWidth 也在扩大。你能想出一种方法来做到这一点,同时保持线宽不变吗?

4

1 回答 1

1

您可以使用customActionWithDuration增加半径(和恒定线宽)重新绘制路径,而不是使用scale. 就像是:

    // ... All as before, except...    
    // myCircle.runAction(scale)
    typealias ActionBlock = ((SKNode!, CGFloat) -> Void)
    let ab: ActionBlock = { (node, value) in
        if let drop = node as? SKShapeNode {
            let myPath: CGMutablePathRef = CGPathCreateMutable()
            CGPathAddArc(myPath, nil, 0, 0, initialRadius * (1.0 + value * 9.0 / duration) , 0, M_PI * 2, true)
            drop.path = myPath
        }
    }

    let newScale = SKAction.customActionWithDuration(duration, actionBlock: ab)
    myCircle.runAction(newScale)
于 2014-07-21T15:23:12.397 回答