2014-04-29 3 views
0

이 코드를 사용하여 SKSpriteNode를 만들고 physicsBody를 원으로 만들었습니다. 그 사용자가 물리학자를 만졌는지 어떻게 확인할 수 있었습니까?물리학 분야의 접촉을 감지하는 방법 신체 부위?

self = [super initWithColor:[SKColor clearColor] size:CGSizeMake(200, 200)]; 
//... 
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.size.width/2.0f]; 
self.userInteractionEnabled = YES; 

답변

0

가장 쉬운 해결책은 당신이 필요로하는 크기로, 두 번째 눈에 보이지 않는 스프라이트를 작성하고 당신에 터치를 기록 할 영역 바로 위에 배치하는 것입니다.

다른 옵션은 다음과 같이 터치 방식으로 좌표 유효한 터치 트리거와 실제 터치에 그들을 비교할 ALL 좌표를 저장하는 것입니다 :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint touchLocation = [touch locationInNode:self.scene]; 

    NSLog(@"%@", NSStringFromCGPoint(touchLocation)); 
    // Compare the touchLocation coordinate against your list of acceptable coordinates... 
} 
+0

CGPathContainsPoint를 사용하여 해결 방법을 찾았습니다. 나는 대답으로 그것을 게시했다. – Ramis

1

I했던이를 사용하여 내 문제에 대한 발견 솔루션 코드 :

CGMutablePathRef pathRef; 
// Fill pathRef with points and create phisycs body using pathRef. 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint touchLocation = [touch locationInNode:self.scene]; 

    if (CGPathContainsPoint(pathRef, nil, touchLocation, NO)) { 
     // If we are here it means user did touche physic body. 
    } 
} 
관련 문제