2011-01-19 1 views
1

나는 몇 개의 출구 포인트를 가지고 bool 값을 반환하는 방법을 가지고있다. 그러나 제대로 작동하지 않는 것, 그래서 내가 자동 변수를 YES 값을 반환하는 보려면 자동 중단 점을 설정하고 싶습니다, 그래서 모든 변수 및 계산 디버거에서 확인할 수 있습니다. YES 값이 반환 될 때마다 디버거를 중지하고 싶습니다.메서드가 특정 값을 반환 할 때 "스마트"중단 점을 Xcode에 설정하는 방법은 무엇입니까?

비슷한 스마트 브레이크 포인트를 objc_exception_throw으로 설정 했으므로 가능하다는 것을 알고 있습니다. 그 방법은 확실하지 않습니다.


가 (여기서 사람, 당신은 예외 중단 점을 설정할 수있는 방법 데 도움이 : 중단 점 창에서을 (실행 ->보기 -> 중단 점) "위치"로 "브레이크 포인트"로 objc_exception_throw 입력 libobjc.A.dylib)

편집 :이 방법은

- (void)update:(ccTime)delta { 
    if ([self collisionOccured]) { 
     NSLog(@"A collision occured"); 
    } 
} 
를 통해이라고

- (BOOL)collisionOccured { 
    // Assumption: helicopter is of square shape (collision calculated by radius), walls are rectangles 
    // This approach is based on the solution seen here: http://stackoverflow.com/questions/401847/circle-rectangle-collision-detection-intersection/402010#402010 

    float helicopterImageWidth = [helicopter texture].contentSize.width; 
    float wallImageWidth = [[walls lastObject] texture].contentSize.width; 
    float wallImageHeight = [[walls lastObject] texture].contentSize.height; 
    float helicopterCollisionRadius = helicopterImageWidth * 0.4f; 

    CGPoint helicopterPosition = helicopter.position; 


    int numWalls = [walls count]; 
    for (int i = 0; i < numWalls; i++) { 
     CCSprite *wall = [walls objectAtIndex:i]; 

     if ([wall numberOfRunningActions] == 0) { 
      // The wall is not moving, we can skip checking it. 
      continue; 
     } 

     CGPoint wallPosition = wall.position; 

     float helicopterDistanceX = abs(helicopterPosition.x - wallPosition.x - wallImageWidth/2); 
     float helicopterDistanceY = abs(helicopterPosition.y - wallPosition.y - wallImageHeight/2); 

     if (helicopterDistanceX > (wallImageWidth/2 + helicopterCollisionRadius)) { return NO; } 
     if (helicopterDistanceY > (wallImageHeight/2 + helicopterCollisionRadius)) { return NO; } 

     if (helicopterDistanceX <= (wallImageWidth/2)) { return YES; } 
     if (helicopterDistanceY <= (wallImageHeight/2)) { return YES; } 

     float cornerDistance_sq = powf((helicopterDistanceX - wallImageWidth/2), 2) + 
           powf((helicopterDistanceY - wallImageHeight/2), 2); 

     return (cornerDistance_sq <= powf(helicopterCollisionRadius, 2)); 
    } 

    // this should not occur 
    return NO; 
} 

: 내가하고 싶은 특정 코드는 그것을 사용하는

문제는 업데이트 방법이 인수로 delta (시간이 경과 됨)이 걸리므로 프레임별로 어떤 일이 발생하는지 확인할 수 없습니다. 실행을 계속할 때마다 다른 장면이 표시됩니다. 당신은 그냥 그렇지 않으면 ret

에 시계 포인트를 설정할 수 있습니다

- (BOOL)someMethod { 
    BOOL ret = NO; 
    if (something) { 
     ret = YES; 
    } else if (something_else) { 
     ret = YES; 
    } 
    // ... and so on 
    return ret; 
} 

당신은 : 로컬 반환 변수를 사용하는 경우

+0

Objective-C에서 Run-> Stop을 통해 objc_exception_throw 중단 점을 토글 할 수도 있습니다. 예외 –

답변

1

조건부 중단 점을 설정할 수 있습니다. update:

- (void)update:(ccTime)delta { 
    BOOL collided = [self collisionOccured]; 
    if (collided) { 
     NSLog(@"A collision occured"); 
    } 
} 

에 약간의 비틀기 사용하면 BOOL의 할당 (즉, if 라인), 다음은 "메시지 버블을"블루 중단 화살표를 마우스 오른쪽 버튼으로 클릭하고 선택한 후 정상적으로 중단 점을 설정할 수 있습니다 조건으로 collided을 추가하십시오. 추가 변수는 릴리즈 빌드 모드에서 최적화되어야합니다.

0

(I 코드의적인 Cocos2D를 사용하고 있습니다) 아마도 코드를 단계별로 실행하는 것으로 계속 될 것입니다. 조건부 중단 점의 영리한 조합을 사용하면 모든 호출을 중단하지 않아도됩니다. objc_exception_throw과 같이 메서드 중단 점을 설정하면 호출 할 때마다 중지되고 호출하는 사이트에서 반환 값을 깨는 것이 너무 늦어서 어떻게 얻었는지 파악할 수 없기 때문에 작동하지 않습니다.

코드를 게시 할 수 있으면 디버깅 전략에 관해보다 구체적인 도움을 줄 수 있습니다. 행운을 빕니다. :-)

+0

위 코드를 추가했습니다. – antalkerekes

관련 문제