ios - swift:将 SKShapeNode 转换为 SKSpriteNode -> 无纹理

标签 ios swift sprite-kit skspritenode skshapenode

我试图通过首先将 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/

相关文章:

ios - 在 SwiftUI 中将形状设为父 View 的大小

ios - 将地理点分为经纬度

ios - 如何在导航栏中删除此类颜色?

ios - 如何阻止 Sprite 从特定表面反弹

ios - 展开 segue 以查看包含 SpriteKit 的 SKView 的 Controller 非常慢

objective-c - 使用 Sprite Kit 移动节点

ios - 从 yyyy-MM-dd'T'HH :mm:ssZ 创建日期

ios - Xcode 7 iOS9 字体不再被识别

ios - 当我移动到另一个 View Controller 时弹出显示

ios - XCTEST addUIInterruptionMonitor false 选择取消按钮