0

In my application I have it so that whenever two round images intersect with each other the game ends, but the problem that I am seeing is that the two images are actually intersecting before they actually touch one another. I have tried multiple examples to try to solve my problem, but none of them seem to work. Here is the code I have implemented as of now...

creature.layer.backgroundColor=[[UIColor clearColor] CGColor];
creature.layer.cornerRadius=25;
creature.layer.masksToBounds = YES;

ball1.layer.backgroundColor=[[UIColor clearColor] CGColor];
ball1.layer.cornerRadius=20;
ball1.layer.masksToBounds = YES;

Is there anything that I can do so that that instead of the frames of the images colliding it is the center of the images that collide?

  • Do you really want to know when the centers collide, or when the outside of the circles do? – rdelmar May 17 '14 at 01:31
  • Either would be fine because in the end for what I am creating it would not matter what I base the collision off of. – user3321574 May 17 '14 at 02:09

1 Answers1

1

Firstly, UIKit does not contain the right tools for collision detection (or game development). Why don't you try SpriteKit? Now, to try and answer your question, the best way I can think of using UIKit would be to approximate your rounded corners using CGRect (3 of them per corner should do the trick). You could also do this approximation using 3 or more arbitrary points on one rounded corner's path and check if either of them is inside the other's object path (this implies that you'd use CGPaths to describe the rounded corners rectangle not the layer's corner radius.

Rad'Val
  • 8,895
  • 9
  • 62
  • 92