Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Game with Sprite Kit Artificial Intelligence and Sound Spawning Enemies

Murat Murat
Murat Murat
2,903 Points

Distance to a node?

How could we spawn the space dogs with a distance to each other? Do we use SKConstraint, distance:toNode , distance:toPoint:inNode? I am trying to make a game and want to place some amount of images randomly but with some distance to each other. Could you provide a sample code related to space dog.

Thank you,

Jack Colley
Jack Colley
4,257 Points

It may not be the prettiest way to do it but from my understanding of your question. You could compare the x and y value's of the already existing space dogs and adjust the new ones accordingly.