使用SKCropNode时出现奇怪的黑色边框

时间:2016-02-02 23:52:44

标签: ios swift sprite-kit crop

我正在使用SpriteKit进行游戏,我有一个正方形的SKSpriteNode,它的角落我想绕过它。我不能使用SKShapeNode,因为我想最终添加一个渐变。所以我决定使用SKCropNode来裁剪它,但是当我这样做时,会出现这样一个奇怪的黑色边框:

enter image description here

如果我不尝试裁剪它,它看起来像这样:

enter image description here

这是我用来创建和裁剪它的代码:

    spriteNode = SKSpriteNode(color: color.skColor, size: CGSize(width: TileSize, height: TileSize))

    let borderRadius: CGFloat = 2
    let roundPath = CGPathCreateWithRoundedRect(CGRect(x: -TileSize / 2, y: -TileSize / 2, width: TileSize, height: TileSize), borderRadius, borderRadius, nil)

    let mask = SKShapeNode()
    mask.path = roundPath
    mask.fillColor = SKColor.whiteColor()
    mask.strokeColor = SKColor.whiteColor()

    let cropNode = SKCropNode()
    cropNode.maskNode = mask

    let shadow = SKSpriteNode(color: SKColor.blackColor(), size: CGSize(width: TileSize, height: TileSize))
    shadow.colorBlendFactor = 1
    shadow.alpha = 0.25

    let radius: CGFloat = 3.5
    shadow.position = CGPoint(x: radius / 2, y: radius / 2)

    let effectNode = SKEffectNode()
    effectNode.filter = CIFilter(name: "CIGaussianBlur", withInputParameters: [kCIInputRadiusKey: radius])
    effectNode.zPosition = spriteNode!.zPosition - 1
    effectNode.addChild(shadow)

    let bluredTile = SKShapeNode(path: roundPath)
    bluredTile.addChild(effectNode)

    cropNode.addChild(spriteNode!)

    addChild(bluredTile)
    addChild(cropNode)

为什么会这样,我怎么能阻止它?

0 个答案:

没有答案