2010-02-14 5 views
2

이 GameViewController.mCGPathContainsPoint 질문이 있으십니까?

-(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]가 일어나기를 원합니다. 새가 모양 안에 갇혀 있지 않으면 채워집니다. 어떤 생각이라도 대단히 감사하겠습니다.

답변

1

난 정말 당신의 코드를 이해하지 않지만, 나는 이것이 당신이 원하는 무엇을 기본적으로 상상 : 경로가 처음에 단지 라인처럼

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 
} 

둘째로, 나는 당신이 옳은 일을 반복하지 않는다고 확신합니다. 반복 할 때마다 경로를 확장하는 것처럼 보이지만 전체 경로를 먼저 작성한 다음 모든 조류를 반복해야한다고 생각합니다. 그러나 오해가 될 수 있습니다.

+0

레벨에 따라 2-26 마리의 새가 날 수 있습니다. 그들 중 하나가 형성되는 모양 안에 포함되어 있다면, 나는 [doDie]가 일어나길 원합니다. 나를 미치게하고있어. 나는 내가 원하는 것을 정반대로 얻을 수있다. 새가 그 모양에 포함되어 있다면 그 부분이 색깔로 채워지지 않도록 내가 만든 방법을 알아낼 수 없습니다. 나는 너의 제안을 시도하고 내가 생각해내는 것을 보게 될 것이다. – NextRev

+0

이 fillpath는 무엇입니까? 어디서나 동일한 질문에 대해 인터넷 검색을하는 동안 나는 그것을 그대로보고 있습니다. 설명 없음. –

관련 문제