0

I designed an app where the user taps the ball as many times as they can within 30 seconds called iTapping. In the game, the user is able to tap anywhere on the screen for the ball to be tapped. I thought of editing the app so that there would be 'dead spots' where the user would not be able to tap the ball. For example, if the ball is in the upper right-hand corner (lets say in an area of about 100 sq. pts.), and the user taps the ball nothing happens. How would I code this? Please let me know if this is not clear enough.

Here is the .m file:

CGPoint Destination;
CGFloat xamt, yamt; 
CGFloat speed21 = 40;
CGFloat xMin21 = 24;
CGFloat xMax21 = 297;
CGFloat yMin21 = 74;
CGFloat yMax21 = 454;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view]; 
if ([self Intersecting:location :Ball]) {
    number21++;

    int xRange = xMax21 - xMin21;
    int yRange = yMax21 - yMin21;

    int xRand = (arc4random() % xRange) + xMin21;
    int yRand = (arc4random() % yRange) + yMin21;

    Destination = CGPointMake(xRand, yRand);
    xamt = ((Destination.x - Ball.center.x) / speed21);
    yamt = ((Destination.y - Ball.center.y) / speed21);


    if (number21 == 65) { 
        [timer invalidate];
      }
   }
}   

-(BOOL)Intersecting:(CGPoint)loctouch:(UIImageView *)enemyimg {
    CGFloat x1 = loctouch.x;
    CGFloat y1 = loctouch.y;

    CGFloat x2 = enemyimg.frame.origin.x;
    CGFloat y2 = enemyimg.frame.origin.y;
    CGFloat w2 = enemyimg.frame.size.width;
    CGFloat h2 = enemyimg.frame.size.height;

    if ((x1>x2)&&(x1<x2+w2)&&(y1>y2)&&(y1<y2+h2))
        return YES;
    else
        return NO;
}
cory ginsberg
  • 2,907
  • 6
  • 25
  • 37

1 Answers1

2

I suggest to put the touch management back to the ball itself (see this answer). So whenever a touch is received, you can be sure it's clicking on the ball. All you need to do is to check whether the ball is currently in the dead zone, thus ignore the touch.

Community
  • 1
  • 1
ohho
  • 50,879
  • 75
  • 256
  • 383