swift:将SKShapeNode转换为SKSpriteNode - >没有纹理

时间:2015-03-09 11:02:52

标签: ios swift sprite-kit skspritenode skshapenode

我试图通过首先将SKShapeNode转换为纹理来将SKShapeNode转换为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)

1 个答案:

答案 0 :(得分:0)

啊,我明白了!我的z位置错了!创建的形状位于我的背景图像之上,但新创建的精灵并非如此。愚蠢的我......