Iphone 如何防止屏幕上某个区域出现轻敲

Iphone 如何防止屏幕上某个区域出现轻敲,iphone,ios,game-physics,Iphone,Ios,Game Physics,我设计了一个应用程序,用户在30秒内尽可能多地轻拍球,称为iTaping。在游戏中,用户可以在屏幕上的任意位置轻击要轻击的球。我想编辑这个应用程序,这样就有了“死点”,用户就不能轻触球了。例如,如果球在右上角(比如在大约100平方分的区域内),并且用户轻敲球,则不会发生任何情况。我将如何编写此代码?如果这不够清楚,请告诉我 以下是.m文件: CGPoint Destination; CGFloat xamt, yamt; CGFloat speed21 = 40; CGFloat xMin21

我设计了一个应用程序,用户在30秒内尽可能多地轻拍球,称为iTaping。在游戏中,用户可以在屏幕上的任意位置轻击要轻击的球。我想编辑这个应用程序,这样就有了“死点”,用户就不能轻触球了。例如,如果球在右上角(比如在大约100平方分的区域内),并且用户轻敲球,则不会发生任何情况。我将如何编写此代码?如果这不够清楚,请告诉我

以下是.m文件:

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;
}
CGPoint目的地;
CGXAMT,yamt;
CG21=40;
cgmin21=24;
cgax21=297;
CGYmin21=74;
cGx21=454;
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[[event AllTouchs]anyObject];
CGPoint location=[触摸位置视图:self.view];
if([自交:位置:球]){
数字21++;
int xRange=xMax21-xMin21;
int-yRange=yMax21-yMin21;
int xRand=(arc4random()%xRange)+xMin21;
int yRand=(arc4random()%yRange)+yMin21;
目的地=CGPointMake(xRand、yRand);
xamt=((Destination.x-Ball.center.x)/speed21);
yamt=((Destination.y-Ball.center.y)/speed21);
如果(number21==65){
[计时器失效];
}
}
}   
-(BOOL)相交:(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;

如果((x1>x2)&&(x1y2)&&&(y1我建议将触控管理放回球本身(请参阅)。因此,每当收到触控时,您可以确保它正在点击球。您需要做的只是检查球当前是否在死区,从而忽略触控