質問

これは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];
}
あなたのパスが最初にちょうどラインである、と私は何もその中に含まれることになるとは思わないように

に見えます。あなたはより徹底的に客観的に説明している場合(私たちはどのように多くの鳥をチェックしている?それはそれぞれに同じパスですか?)私たちはさらに助けることができます。

編集ます:

うーむ、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