更新:看起来iOS 10已经修复了这个问题。我升级到Swift 3和Xcode 8,一切都如愿以偿。
我已经碰到过几次这个问题了,我不知道它是SKCropNode中的一个bug,还是我只是在滥用它。也许我遗漏了一些文档来解释为什么会发生这种情况?
我有一个具有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)

发布于 2016-09-04 18:44:02
SKShapeNode被窃听了,最好不惜一切代价避免它。使用它创建形状,然后将其转换为用于SKSpriteNode的纹理。
https://stackoverflow.com/questions/39320085
复制相似问题