Frage

Dies ist in 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];
    }


}

Dies ist in 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];
            }
        }
    }
}

Ich kann nicht herausfinden, was an dem Ort geht, an dem ich "Was geht hier",? Ich möchte es so, dass [Dodie], wenn ein Vogel in der Form gefangen ist, [Dodie] stattfindet. Wenn der Vogel nicht in der Form gefangen ist, wird er ausgefüllt. Alle Ideen werden sehr geschätzt.

War es hilfreich?

Lösung

Ich verstehe Ihren Code nicht wirklich, aber ich kann mir vorstellen, dass dies im Grunde das ist, was Sie tun möchten:

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

Es sieht so aus, als wäre Ihr Weg anfangs nur eine Linie, und ich glaube nicht, dass etwas darin enthalten sein wird. Wenn Sie das Ziel gründlicher erklären (wie viele Vögel prüfen wir?

Bearbeiten:

Hmmmm, ok. Das erste ist einfach genug. Um das Füllen zu verhindern, wenn sich ein Vogel auf dem Weg befindet, verwenden Sie keinen anderen Fall. Stellen Sie im iF ein Flag ein, wenn der aktuelle Vogel im Pfad enthalten ist. Füllen Sie nach der Schleife, wenn das Flag nicht eingestellt ist, den Pfad. Also so etwas wie:

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
}

Zweitens bin ich mir ziemlich sicher, dass Sie nicht das Richtige durchlaufen. Es sieht so aus, als ob Sie den Weg jede Iteration erweitern, aber ich denke, Sie sollten zuerst den ganzen Weg bauen und dann alle Vögel durchlaufen, aber ich könnte Missverständnis sein.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top