2

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?

ABakerSmith
  • 22,759
  • 9
  • 68
  • 78
nmokkary
  • 1,219
  • 3
  • 14
  • 24
  • You should generate random position, and then check if there are no nodes there. You should provide more spefic question to get more specific answer. :) – Darvas May 31 '15 at 16:25
  • How can i check the size of shape and the empty space? – nmokkary May 31 '15 at 18:48
  • What are you trying to do ? Maybe a puzzle game? Can you give an example of your idea? – Darvas May 31 '15 at 20:54

1 Answers1

0

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.

sangony
  • 11,636
  • 4
  • 39
  • 55