具有固定轮廓宽度的膨胀圆

具有固定轮廓宽度的膨胀圆

我要达到的效果就像水上的雨滴,波从中心点放射出来。

我创建一个圆形:

    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也正在扩大。您能想到一种方法来保持线宽不变吗?

最佳答案

您可以使用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)

关于ios - 具有固定轮廓宽度的膨胀圆,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24868450/

10-14 22:04