0

I have an UIImageview that contains a circle (The obstacle) and then another UIImageview that contains another image (my character). When my circle hits my character the game ends.

My problem occurs when the game ends on the character touching the UIImageview box that my circle is within, rather than the circle inside the UIImageview box.

The solutions I can think of are:

  • Make the UIImageview rounded to fit my circle.
  • Somehow detect a collision between my characters pixels and the circles pixels rather than the UIImageviews.

Help and ideas would be really appreciated. I am a beginner with xcode.

Thanks!

Nikunj
  • 655
  • 3
  • 13
  • 25
Phil
  • 515
  • 2
  • 6
  • 16
  • Calculate intersection positions of circle. If its top,bottom,left,right from centre character dies, and If its in top left, top right, bottom left, bottom right, character will not die. It seems like character is jumping above the circular object. – Ali Exalter Oct 23 '13 at 11:25
  • can you extend on this so I could give it a try? – Phil Oct 23 '13 at 12:53

1 Answers1

6

Couple of different techniques:

1)UIView#layer.cornerRadius - Super simple to implement, just set that one property. But really bad for scrolling elements like table views.

2)UIImageView as a mask - Also easy to implement. Basically make a square image with a transparent circle in the middle and slap it on top of your view with a new UIImageView. If your circle design has some reflections or styling, this might make your life easier.

3)Custom drawing - Make a UIView subclass and override drawRect to draw your image and clip it to a circular path.

Hope that helps!

EDIT:

You can read this answers.

1)Fill an UIBezierPath with a UIImage

2)iOS: Inverse UIBezierPath (bezierPathWithOvalInRect)

3)How to mask a square image into an image with round corners in the iPhone SDK?

Community
  • 1
  • 1
Bhavesh
  • 1,422
  • 1
  • 12
  • 31
  • Thanks for help. Do I need to import to be able to us UIView#layer.cornerRadius? Also would I implement it like so: **circle.layer.cornerRadius = 10;** **circle.layer.masksToBounds = YES;** – Phil Oct 23 '13 at 13:02
  • Yes, you have to import QuartzCore Framework whenever use have to use CALayers and Core Animation.You can find great tutorial about layers on this link:-http://www.raywenderlich.com/2502/calayers-tutorial-for-ios-introduction-to-calayers-tutorial – Bhavesh Oct 23 '13 at 13:15
  • after reading the guide you posted previous (which I read and understand to a certain degree) i'm finding it difficult to combine the layers idea with my previous code of moving the circle across the screen. "**circle.center = CGPointMake(circle.center.x - 9, circle.center.y);**". Do i need to completely rewrite my movement code to suit the new layers? – Phil Oct 23 '13 at 15:04