The game should be able to detect "out-of-boundary" events once the finger moves outside the ring. How can I accomplish this?
Presumably you have the center point of the ring (
c), and the radius of the inner and outer segments of the valid portion of the ring (
Then, given any touch point
p, you simply need to perform two point-in-circle tests. The touch is valid (within the ring) if it is both outside the inner circle and inside the outer circle. A point
p is within a circle of radius
r with a center at
c if it satisfies the inequality:
(p.x - c.x)^2 + (p.y - c.y)^2 < r^2
So you need
BOOL insideInner = pow((p.x - c.x), 2) + pow(p.y - c.y, 2) < (ri * ri); BOOL insideOuter = pow((p.x - c.x), 2) + pow(p.y - c.y, 2) < (ro * ro); BOOL isValid = !insideInner && insiderOuter;
to determine if the current touch point is valid (`isValid). You get updated touch positions every touch or drag event, which you can feed to the computation and determine if the touch ever leaves the valid area.
Note that you can factor out a bunch of that math to avoid repeated computation.