A little of background: I have function spawnBubbles(), which uses output of another function determineSpawnPoint().
determineSpawnPoint() returns random CGPoint. There is also action, which spawns SpriteNodes once 0.5 second in the random X coordinate CGPoint.
The problem: as determineSpawnPoint() is random, sometimes 2 or 3 SpriteNodes in a row created nearby, so they intersect with each over.
What do I want to achieve: create a function
func checkForFreeSpace(spawnPoint:CGPoint) -> Bool{
//some code
}
which returns true if there is free space around certain point.
So, basically, when I get new random CGPoint, I want to implement a CGRect around it, and check if this rectangle intersects with some SpriteNodes (speaking in common sense, if there is free space around it)
You can create two CGRects from the point and nodes and use CGRectIntersectsRect function to check whether they intersect. The function returns true if they intersect.
if (CGRectIntersectsRect(rect1, rect2))
{
println("They intersect")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With