-4

-(void)ccTouchesBegan...

UITouch* touch = [touches anyObject];

CGPoint location = [touch locationInView:[touch view]];

Can someone please explain in detail what exactly is going on in these two lines of code. Thanks

Tim
  • 8,932
  • 4
  • 43
  • 64

1 Answers1

1
UITouch *touch = [touches anyObject];

touches is a NSSet of UITouch. The code simply gets one object from touches and assigns it to a variable named touch. This is implicitly assuming that the NSSet hold only one element.

CGPoint location = [touch locationInView:[touch view]];

the above line gets the (x,y) coordinates of the touch in the coordinate system of the view that intercepted the touch. CGPoint is nothing more than a C struct with two float values, x and y.

So bottom line you will obtain the coordinates of the touch in the view.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235