E. Huckabee
E. Huckabee

Reputation: 1808

Use an SKShapeNode for the mask of an SKCropNode (Swift)

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?

Upvotes: 4

Views: 1126

Answers (0)

Related Questions