2014-04-12 3 views
0

내 앱의 버튼으로 SKLabel 노드 설정이 있는데 정상적으로 작동합니다. 이 코드로 SKLabelNode을 회전 할 때, 내 touchesBegan 방법이 더 이상 제대로 실행하고는 SKLabelNode의 접촉이 제대로 등록이 매우 어려워진다 : 여기SKLabelNode를 회전하면 touchesBegan에서 위치를 얻는 것이 어려워집니다.

[_menuButton runAction:[SKAction sequence:@[[SKAction rotateByAngle:M_PI duration:.2], 
               [SKAction moveByX:0 y:-15 duration:.2]]]]; 

내 접촉이 시작되지 방법 :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
UITouch *touch = [touches anyObject]; 
CGPoint location = [touch locationInNode:self]; 
SKNode *node = [self nodeAtPoint:location]; 

CGPoint positionInScene = [touch locationInNode:self]; 
[self selectNodeForTouch:positionInScene]; 

if ([node.name isEqualToString:menuButtonName]) { 
    //Touched Menu Button 
     [self animateMenuAndShow:YES]; 

} 
} 

편집 : 정보의 한 추가 부분은 SKTEffects를 사용하는 것입니다. 대신 self.scene을 기본으로 사용하는 대신 _worldLayer를 사용하여 장면의 모든 요소를 ​​추가해야합니다. 이것이 내 터치 계산을 던질 가능성이 있습니까? 그리고 만약 그렇다면 어떻게 이것을 수정할 수 있습니까?

self.scaleMode = SKSceneScaleModeResizeFill;  
self.anchorPoint = CGPointMake(0.5, 0.5); 

// The origin of the pivot node must be the center of the screen. 
_worldPivot = [SKNode node]; 
[self addChild:_worldPivot]; 

// Create the world layer. This is the only node that is added directly 
// to the pivot node. If you have a HUD layer you would add that directly 
// to the scene and make it sit above the world layer. 
_worldLayer = [SKNode node]; 
_worldLayer.position = self.frame.origin; 
[_worldPivot addChild:_worldLayer]; 

또한 여기 sangony의 조언을 따른 후 내 업데이트 touchesBegan입니다 : 방법

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    { 

    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInNode:_worldLayer]; 
    CGPoint locationInMenu = [touch locationInNode:_menuBackground]; 

    if (CGRectContainsPoint(_menuButton.frame, location)) { 
    //Touched Menu Button 

     if (!self.menuVisible) { 
      [self animateMenuAndShow:YES]; 
     } 
     else 
     { 
     [self animateMenuAndShow:NO]; 
     } 
    } 
} 

EDIT2 M_PI하여 라벨을 회전 한 후 동일한 문제로 처음에는 잘 작동하지만, 실행 :

은 다음은 내 animateMenuAndShow입니다. 메서드

-(void)animateMenuAndShow:(BOOL)show 
{ 
    if (show == YES) { 
     // self.paused = YES; 
     self.menuVisible = !self.menuVisible; 

     [self createMenu]; 


     SKAction *showMenuAction = [SKAction sequence:@[ 
                [SKAction moveTo:CGPointMake(self.size.width/2, self.size.height/2) duration:0.3], 
                [SKAction runBlock:^{ 
                [self jelly:self.menuBackground]; 
                 }], 
                [SKAction waitForDuration:1.5] 
                ]]; 
     [self.menuBackground runAction: showMenuAction completion:^{ 
      self.paused = YES; 
     }]; 


     if (_flipped == YES) { 
      [self.menuBackground runAction:[SKAction sequence:@[ 
                  [SKAction moveByX:0 y:0 duration:.2],[SKAction rotateByAngle:M_PI duration:.2]]]];// [SKAction rotateByAngle:M_PI duration:.2] 
     } 

    } 
    else 
    { 
     self.paused = NO; 

     SKAction *removeMenuAction = [SKAction sequence:@[ 
                 [SKAction   moveTo:CGPointMake(self.size.width/2, -self.size.height + 300) duration:0.3], 
                 ]]; 
     [self.menuBackground runAction:removeMenuAction completion:^{ 
      [self.menuBackground removeFromParent]; 
     }]; 

     self.menuVisible = !self.menuVisible; 


    } 
} 

답변

0

시도해보십시오. touchesBegan 대신

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

    if (CGRectContainsPoint(myLabel.frame, touchLocation)) 
     { 
      [self animateMenuAndShow:YES]; 
     } 
} 
+0

안녕하세요. 제안에 감사드립니다. 나는 touchesBegan : 메소드를 업데이트하여 제안 사항을 수정했지만 잘 작동하지만 메뉴 SKLabel이 회전 한 후에 실제로 사라지거나 표시되는 메뉴를 얻으려면 많은 노력이 필요합니다. 자세한 내용은 위의 편집을 참조하십시오. – DavidNorman

+0

어디서 어떤 상황에서 회전 동작이 호출됩니까? animateMenuAndShow와 연결된 메소드를 확인하는 코드를 보여주십시오. – sangony

+0

Ok는 animateMenuAndShow 메소드로 내 대답을 업데이트했습니다. – DavidNorman

관련 문제