5

I'm trying to convert SKShapeNode into a Sprite node by first converting the SKShapeNode into a texture. However the results is invisible sprite. The Physics body is there normally but no graphics are being displayed. Something wrong with the way I try to convert the SKShapeNode, I suppose but I can't think of what. Do you have sense on what's wrong? ALL HELP APPRECIATED!

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)
Raksha Saini
  • 604
  • 12
  • 28
user3673836
  • 591
  • 1
  • 9
  • 23
  • Is your shapenode visible? I see that you are using a path to initialize it. Is the shapenode visible if you add it to your view? – Christian Mar 09 '15 at 11:42
  • yes, the shapenode works fine, if i add it into view. – user3673836 Mar 09 '15 at 12:55
  • @user3673836 Sounds like you resolved the issue on your own. You might want to add the answer for other people to learn and I will remove my answer given it doesn't resolve the problem =) – Skyler Lauren Mar 09 '15 at 15:37

1 Answers1

0

Ahh I got it! My z-position was wrong! The created shape was on top of my backgrond image but the newly created sprite wasn't. Stupid of me...

user3673836
  • 591
  • 1
  • 9
  • 23