当我在层次结构中添加额外的SKNode子节点时,SKCropNode失败 [英] SKCropNode fails when I add extra SKNode children in hierarchy

查看:489
本文介绍了当我在层次结构中添加额外的SKNode子节点时,SKCropNode失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:iOS 10已修正此问题。我升级到Swift 3和Xcode 8,一切都按预期工作。

这个问题,现在几次,我不知道它是一个在SKCropNode中的错误,或者如果我只是滥用它。也许有一些文档,我缺少解释为什么会发生这种情况?

I've run into this issue a couple times now and I can't tell if it's a bug in SKCropNode or if I'm just misusing it. Perhaps there's some bit of documentation I'm missing to explain why this is happening?

我有一个裁剪节点100x100矩形形状作为掩码。

I have a crop node with a 100x100 rectangle shape as the mask. If I place a blue circle inside it, it gets cropped properly.

// 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中,并将该容器放在同一个裁剪节点中时,裁剪失败。

Now, when I place that same circle inside of an otherwise empty SKNode and place that container inside the same crop node, cropping fails.

// 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)

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

But a sprite in that same container seems to be cropped fine.

// 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)

推荐答案

SKShapeNode是bug,最好避免它在所有成本。使用它来创建您的形状,然后将其转换为纹理以供SKSpriteNode

SKShapeNode is bugged, best to avoid it at all costs. Use it to create your shapes, then convert it to a texture for use with SKSpriteNode

这篇关于当我在层次结构中添加额外的SKNode子节点时,SKCropNode失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆