I want to add SKShapeNode
to random position, using Sprite Kit, until the screen getting full.
How can I find the empty space in screen?
I want to add SKShapeNode
to random position, using Sprite Kit, until the screen getting full.
How can I find the empty space in screen?
This is not an off the shelf kind of function in SK. Your only solution would be to create a hack to do what you want. One possible approach might be to create a very small node and place it in various positions on the screen, using a loop. For example (x,y position), 0,0 -> 4,0 -> 8,0 and so on...
You can use the func intersectsNode(_ node: SKNode) -> Bool
to see if this node intersects any other node.
Another approach might be to use the same kind of logic but use func containsPoint(_ p: CGPoint) -> Bool
instead.
Both approaches would be processor intensive so you should only run them sparingly.