4

How can I use an SKShapeNode for the mask of an SKCropNode? My code currently creates an SKShapeNode circle and then sets the crop node mask to it

shapeNode = SKShapeNode(circleOfRadius: 50)
shapeNode.fillColor = UIColor.red
shapeNode.lineWidth = 1
shapeNode.position = CGPoint(x: 0, y: 0)
shapeNode.zPosition = 4

cropNode = SKCropNode()
cropNode.maskNode = shapeNode
cropNode.addChild(Node)

But when I add the Node as a child of the cropNode it doesnt draw anything but a red circle (exactly as i set it to do)

Is there any way to use an SKShapeNode as the mask of an SKCropNode?

-Update-

I figured out how to make an SKSpriteNode drawn from the SKShapeNode

shapeNode = SKShapeNode(circleOfRadius: 60)
shapeNode.fillColor = UIColor.red

let shapeTexture = view.texture(from: shapeNode)
textureNode = SKSpriteNode(texture: shapeTexture)
textureNode.position = CGPoint(x: 0, y: 0)
textureNode.zPosition = 3

cropNode.maskNode = textureNode
cropNode.addChild(tileMap2)
self.addChild(cropNode)

But now the SKCropNode isnt working when applied to the SKSpriteNode how do I fix this?

E. Huckabee
  • 1,788
  • 1
  • 13
  • 29
  • I remember this pain, but not the solution. – Confused Nov 13 '17 at 14:21
  • Here’s an answer I vaguely remember using the approach of, and getting it to work, I think: https://stackoverflow.com/questions/39967815/crop-mask-circular-image-node-in-sprite-kit-gives-jagged-edges – Confused Nov 13 '17 at 14:33
  • Did you get the view? – Confused Nov 13 '17 at 14:39
  • Sorry for this dribbling out of comments... I'm trying to recall what I did whilst reviewing other answers. I think I had to draw (add) the skshapenode to a view and then get that view. – Confused Nov 13 '17 at 14:41
  • not sure why you are messing with the zPosition on your mask node, I would get rid of that, other than that it should work fine – Knight0fDragon Nov 14 '17 at 00:59
  • Man the udpate worked, thanks a ton – Marin Feb 20 '18 at 19:49

0 Answers0