这是在GameViewController.m

-(void)fillMutablePath{



    CGPoint movePoint = CGPointFromString([pointsToFillArray objectAtIndex:0]);

    CGPathMoveToPoint(fillPath, NULL, movePoint.x, movePoint.y);
    for (int i=0; i<[pointsToFillArray count]; i++) {
        CGPoint tempPoint = CGPointFromString([pointsToFillArray objectAtIndex:i]);
        CGPathAddLineToPoint(fillPath, NULL, tempPoint.x, tempPoint.y);
        CGContextAddPath(gameViewObj._myContext, fillPath);
        CGContextFillPath(gameViewObj._myContext);

        if(CGPathContainsPoint(fillPath, nil, "What goes here?", false)){
            [self doDie];
        }
else {
  CGContextFillPath(gameViewObj._myContext);
}
        CGPathRelease(fillPath);
        [pointsToFillArray removeAllObjects];
    }


}

这是在GameView.m

-(CGPoint) GetBirdPosition:(CGPoint) PtPoint :(int) BirdNumber{
    CGPoint Temp=PtPoint;
    BOOL isTouch=TRUE;
    while (isTouch)
    {
        isTouch=FALSE;
        if(playField[(int) Temp.x][(int) Temp.y]==2)
        {
            isTouch=TRUE;
            if(playField[(int) Temp.x+1][(int) Temp.y] == 2 || playField[(int) Temp.x-1][(int) Temp.y] == 2)
            {
                pos[BirdNumber].y = -pos[BirdNumber].y;
                Temp.y+=pos[BirdNumber].y;

            }
            else if(playField[(int) Temp.x][(int) Temp.y+1] == 2 || playField[(int) Temp.x][(int) Temp.y-1] == 2)
            {
                pos[BirdNumber].x = -pos[BirdNumber].x;
                Temp.x+=pos[BirdNumber].x;
            }

        }
    }
    return Temp;
}

-(void)flyingBird:(NSTimer *)timer {

    if(appDelegate.gameStateRunning == YES){

        for (int i=0; i< [birdImageViewArray count];i++)
        {
            UIImageView* birdImageView=[birdImageViewArray objectAtIndex:i];

            CGPoint Temp=CGPointMake(birdImageView.center.x + pos[i].x , birdImageView.center.y + pos[i].y);
            birdImageView.center =[self GetBirdPosition:Temp:i];

            if(playField[(int) birdImageView.center.x][(int) birdImageView.center.y]==3){

                [[NSNotificationCenter defaultCenter] postNotificationName:@"LineCrossed" object:nil];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayDieSound" object:nil];
            }
        }
    }
}

我想不出在我写的“什么到这里”的地方发生的事情?我希望它这样,如果鸟被捕获内的形状,然后选择[多迪]发生。如果鸟就不会捕获在形状内,它就会被填充。任何想法是不胜感激。

有帮助吗?

解决方案

我真的不理解你的代码,但我想这基本上是你想要做什么:

CGPoint Temp=CGPointMake(birdImageView.center.x + pos[birdNum].x , birdImageView.center.y + pos[birdNum].y);
if(CGPathContainsPoint(fillPath, nil, [myGameView GetBirdPosition:Temp:i], false)){
    [self doDie];
}

它看起来像你的路径是最初只是一条线,我不认为任何事情都会被包含在其中。如果你更彻底地解释目标(有多少鸟儿,我们检查?是不是每个相同的路径?)我们可以进一步帮助。

编辑:

Hmmmm,OK。第一件事情是很简单的。为了防止填充如果有鸟的路径,不使用其他案例。在如果,如果目前的禽流包含在路径设置一个标志。然后在循环后,如果未设置标志,填补了路径。所以是这样的:

BOOL pathContainsBird = NO;
for (int i=0; i<[pointsToFillArray count]; i++) {
    //bunch of stuff
    if(CGPathContainsPoint(fillPath, nil, "What goes here?", false)){
        pathContainsBird = YES;
        [self doDie];
    }
}
if(!pathContainsBird) {
    //fill path here
}

二,我敢肯定你是不是通过正确的事情循环。它看起来像您展开路径每次迭代,但我认为你应该通过所有的鸟儿先建全路径,然后循环,但我可能是误解。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top