5

更新:看起来 iOS 10 已经修复了这个问题。我升级到 Swift 3 和 Xcode 8,一切都按预期工作。


我现在已经遇到过几次这个问题,我不知道这是 SKCropNode 中的错误还是我只是在滥用它。也许我缺少一些文档来解释为什么会发生这种情况?


我有一个 100x100 矩形形状的裁剪节点作为蒙版。如果我在其中放置一个蓝色圆圈,它会被正确裁剪。

// Create a crope node with a small square.
let cropNode = SKCropNode()
let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
cropNodeMask.fillColor = UIColor.whiteColor()
cropNode.maskNode = cropNodeMask
self.addChild(cropNode)

// Create a blue circle and put it in the crop node.
let blueCircle = SKShapeNode(circleOfRadius: 110)
blueCircle.fillColor = UIColor.blueColor()
blueCircle.strokeColor = UIColor.clearColor()
cropNode.addChild(blueCircle)

在此处输入图像描述


现在,当我将同一个圆圈放在一个空的 SKNode 内并将该容器放在同一个裁剪节点内时,裁剪失败。

// Create a crope node with a small square.
let cropNode = SKCropNode()
let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
cropNodeMask.fillColor = UIColor.whiteColor()
cropNode.maskNode = cropNodeMask
self.addChild(cropNode)

// Create a container to hold the circle.
let container = SKNode()
cropNode.addChild(container)

// Create a blue circle and put it in the container.
let blueCircle = SKShapeNode(circleOfRadius: 110)
blueCircle.fillColor = UIColor.blueColor()
blueCircle.strokeColor = UIColor.clearColor()
container.addChild(blueCircle)

在此处输入图像描述


但是同一个容器中的精灵似乎被裁剪得很好。

// Create a crope node with a small square.
let cropNode = SKCropNode()
let cropNodeMask = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 100, height: 100))
cropNodeMask.fillColor = UIColor.whiteColor()
cropNode.maskNode = cropNodeMask
self.addChild(cropNode)

// Create a container to hold the sprite.
let container = SKNode()
cropNode.addChild(container)

// Create a spaceship and add it to the container.
let spaceshipNode = SKSpriteNode(imageNamed: "Spaceship")
spaceshipNode.anchorPoint = CGPointZero
container.addChild(spaceshipNode)

在此处输入图像描述

4

1 回答 1

4

SKShapeNode 被窃听,最好不惜一切代价避免它。使用它来创建您的形状,然后将其转换为纹理以与 SKSpriteNode 一起使用

于 2016-09-04T18:44:02.437 回答