我试图通过首先将 SKShapeNode 转换为纹理来将 SKShapeNode 转换为 Sprite 节点。然而结果是看不见的 Sprite 。物理实体通常在那里,但没有显示图形。我想我尝试转换 SKShapeNode 的方式有问题,但我想不出是什么。你知道出了什么问题吗?感谢所有帮助!

let createdShape = SKShapeNode(path: path)
createdShape.physicsBody = SKPhysicsBody(edgeLoopFromPath: createdShape.path)
createdShape.physicsBody?.categoryBitMask = PhysicsCategory.Shape
createdShape.physicsBody?.contactTestBitMask = PhysicsCategory.None
createdShape.name = "paintedArea"
createdShape.strokeColor = shapeBorderColor
createdShape.lineWidth = 5.0
createdShape.fillColor = shapeFillColor
createdShape.alpha = 1.0
createdShape.zPosition = shapeZPosition
let texture = view?.textureFromNode(createdShape)
println(texture?.description)
let sprite = SKSpriteNode(texture: texture)
sprite.physicsBody = createdShape.physicsBody
sprite.position = createdShape.position
sprite.color = UIColor.blueColor()
self.addChild(sprite)

最佳答案

啊我明白了!我的 z 位置错了!创建的形状在我的背景图像之上,但新创建的 Sprite 不在。愚蠢的我...

关于ios - swift:将 SKShapeNode 转换为 SKSpriteNode -> 无纹理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28940408/

10-11 14:52