0

I want to make a game in swift (xcode7) and I have a ball which may intersect with obstacles. But I've got different levels so I can't simply use CGRectIntersectsWithCGRect. Only if I use a switch, which would be the longest in the world and wouldn't look that nice..

So in my head I've a method like this:

ball.intersectsWithRect()->CGRect

or: CGRectIntersectsRect(ball.frame, /*anyframe / anyview.frame*/)

But I couldn't find anything like this. Is that even possible? Or is there even a simpler way to do it?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Sam
  • 819
  • 2
  • 7
  • 17
  • 2
    What's wrong with looping through all your obstacles (keep them in an array, or loop through subviews) and using `CGRectIntersectsWithCGRect`? – Hamish Feb 27 '16 at 16:19
  • 1
    A more specific explanation of your problem will probably get you better answers. There are a number of techniques commonly used for efficient hit detection but it's hard to know which if any would help you. One place to start might be with `quadtree`s: http://stackoverflow.com/questions/4981866/quadtree-for-2d-collision-detection – Jonah Feb 27 '16 at 16:53

0 Answers0