【问题标题】:CGRectContainsPoint using shape opposed to frameCGRect 包含使用与框架相对的形状的点
【发布时间】:2015-09-14 22:21:58
【问题描述】:

所以我们在这里进行了检测

-(void)checkInFOVWithPlayer:(Player *)player andEnemy:(Player *)enemy {
    SKNode *fovNode = [player childNodeWithName:player.playersFOVName];

    SKNode *node = [self childNodeWithName:@"enemy"];

    CGPoint newPosition = [self convertPoint:node.position toNode:fovNode.parent];

    if (CGRectContainsPoint(fovNode.frame, newPosition)) {
        [self playerAimAtEnemy:enemy withPlayer:player];
    }
}

以及我们对视野的实现

SKShapeNode *fov = [SKShapeNode node];
UIBezierPath *fovPath = [[UIBezierPath alloc] init];
[fovPath moveToPoint:CGPointMake(0, 0)];
[fovPath addLineToPoint:CGPointMake(fovOpposite *-1, fovDistance)];
[fovPath addLineToPoint:CGPointMake(fovOpposite, fovDistance)];
[fovPath addLineToPoint:CGPointMake(0, 0)];
fov.path = fovPath.CGPath;
fov.lineWidth = 1.0;
fov.strokeColor = [UIColor clearColor];
fov.antialiased = NO;
fov.fillColor = [UIColor greenColor];
fov.alpha = 0.2;
fov.name = @"playerFOV";
[_playerImage addChild:fov];

现在,这行得通。但是,“视野”的检测范围实际上并不是 BezierPath 的边界,实际上是创建图像的 CGRect。

因此,即使在视野之外,检测也会运行。

我很好奇是否有一个简单的解决方法,因为如果我不需要的话,我真的不想走物理身体路径。

【问题讨论】:

    标签: objective-c frame uibezierpath cgrect skshapenode


    【解决方案1】:

    我终于知道需要什么了。

    在那之后,我不得不重绘路径并为每一帧优化它;

    if (CGPathContainsPoint(fovPath.CGPath, nil, newPosition, NO)) {}
    

    结束了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多