-2

How can you spawn SKSpritenodes randomly inside other SKSpritenodes? Maybe using constraints (in Swift)?

For example, I would like circles to spawn in random places inside different square SKSpriteNodes.

Pimgd
  • 5,983
  • 1
  • 30
  • 45
MattJB
  • 13
  • 6

1 Answers1

1

In order to do that, it's much better to use CGRects to contain the object that you are going to spawn.

You can use arc4random_uniform to get a random value for both the X and Y coordinates of the object that you are spawning and then use CGRectContainsPoint to check if the location is inside the CGRect.

Wraithseeker
  • 1,884
  • 2
  • 19
  • 34