My goal is to have 20 pre-made islands randomly placed on an overworld map that don't overlap.
I'd love to hear if anyone has any clever solutions. I can explain what I've tried below, but it's a bit lengthy and I'm not convinced it's the best approach anyway so it's maybe not necessary to read;
At the start of the layout the islands are outside of the layout. They all have an instance variable ID.
Actually what I'm testing is a sprite that's set to the same size and location then pinned to the island tilemap since I can't test if tilemaps are overlapping objects for some reason.
Then that object is placed into two families because that's the only way I can pick two of the same object and differentiate between the two (if family1 is overlapping family 2).
At the start of the layout I call a function (with the islands ID as parameter) to place the first island randomly. Then I check to see if the island is overlapping another island (it's not because it's the first island).
If it is overlapping, I call the same function again with the same island ID.
If it is not overlapping I call the function with the islandID + 1.
And I repeat that until all the islands have been placed.
Or at least that's how it's supposed to happen. In reality what happens is it doesn't see the islands as overlapping so it doesn't call the function again, it goes on to the next island. But I know it can pick the overlapping objects because after all the islands have been placed I check to see if any are overlapping and it is aware that they overlap.
When I don't check to see if that specific instance in the being placed in the function is overlapping (just checking if any islands are overlapping)it runs into the first point of an overlapping island (usually around the 6th island but depends), and then continually calls the same function even if it's not placed somewhere not overlapping.
So I'm sure there's some bug somewhere, but I'm concerned this is just not the right approach and may take too long for the computer to iterate to a configuration that has no overlapping pieces anyway.
Any help anyone has would be appreciated.