Aside from the fact that the question asked here : Draw a hole in a rectangle with SpriteKit? has not satisfactorily been answered in its own right, the most significant difference between the two is that this question requires an absence of workarounds and specifically asks about reversing the functionality of SKCropNodes.
The primary concerns in this question cannot be addressed by the type of hacky ways the above question could be answered due to the randomness of the holes, the number of holes, and the variation in objects to which the holes are to be applied.
Hence the Swiss Cheese example:
Imagine a bunch of randomly sized rectangular SKSpriteNodes filled with various shades of cheese-like colours.
How to make Swiss Cheese out of each by cutting random circles out of each slice of cheese?
If SKCropNodes are the circles, they only leave circular pieces of cheese rather than cutting holes out of the pieces of cheese. Is there a way to invert the behaviour of SKCropNodes so they cut holes instead?
In my total honesty, I'm not really sure to understand deeply what do you want to achieve, but I can try to answer to this question:
..cutting random circles out of each slice of cheese?
In this project I've try to re-build a typical rectangle (the piece of cheese) with random holes, then I've extract these holes and collect them to an array.
Result:
P.S. Don't pay attention to red rectangles, it's just to show you the holes:
If you want the exactly reversed hole, (the negative image), you could use
SKCropNode
with thehole.blendMode
, for example:Substitute this part of the code:
with this part:
Result (another example):
Hope these example and this code help you to obtain your objectives, I've used rectangles to make masks but your could create CGPaths if you need.