Can you mask an SKSpriteNode with another SKSpriteNode

451 Views Asked by At

Just ask the title asks, I am wondering if this is at all possible. Most examples of the SKCropNode use a texture or a shape. What I want to accomplish is a mask of a custom shape. Let me know if there's a way!

1

There are 1 best solutions below

2
Ralph On

You could mask a node by giving it a child node where the child node's zPosition is greater than the parent's. And then, of course, you'd have to position the child node correctly on top of the parent node -but this should be easy as the child node's position is located relative to the parent node (i.e. if parent has position (25, 30) in the scene, and you set child.position = CGPoint(x:5, y:0), the child's position in the scene would be (30, 30)). Also, if the parent node moves, the child node moves with it.