문제

이것은 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];
            }
        }
    }
}

내가 "여기에 간다"를 쓴 곳에서 무슨 일이 일어나는지 알 수 없습니까? 새가 모양에 갇히면 [Dodie]가 발생하기를 원합니다. 새가 모양 안에 갇히지 않으면 채워집니다. 어떤 아이디어라도 대단히 감사합니다.

도움이 되었습니까?

해결책

나는 당신의 코드를 정말로 이해하지 못하지만 이것이 기본적으로 당신이하고 싶은 일이라고 생각합니다.

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];
}

그것은 당신의 길이 처음에는 단지 한 줄인 것처럼 보이며, 나는 그 안에 어떤 것이 포함될 것이라고 생각하지 않습니다. 목표를 더 철저하게 설명한다면 (우리가 몇 개의 새를 확인하고 있습니까? 각각에 대해 동일한 경로입니까?) 더 도움이 될 수 있습니다.

편집하다:

흠, 좋아. 첫 번째는 충분히 간단합니다. 조류가 경로에있는 경우 충전을 방지하려면 다른 케이스를 사용하지 마십시오. IF에서 현재 새가 경로에 포함되어 있으면 깃발을 설정하십시오. 루프 후 플래그가 설정되지 않으면 경로를 채우십시오. 그래서 :

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