2013-10-12 2 views
0

현재이 코드를 사용하여 CCSprite (플레이어) 객체를 마지막 터치에 맞 춥니 다. 문제는 회전이 매우 불안정 해지고 매우 부드럽게 보이지 않는다는 것입니다.Cocos2D에서 터치하도록 CCSprite를 회전하십시오.

CGPoint playerPos = [player position]; 
CGPoint diff = CGPointMake(currentPoint.x-lastPoint.x, currentPoint.y-lastPoint.y); 
CGPoint playerNewPos = ccpAdd(playerPos, diff); 
[player setRotation:-CC_RADIANS_TO_DEGREES(atan2(playerNewPos.y-playerPos.y, playerNewPos.x-playerPos.x))]; 

이 코드를 어떻게 더 부드럽고 유동적으로 만들 수 있습니까?

CCRotateTo를 사용해 보았지만 같은 문제가 발생합니다. 사전에

감사

답변

0

이 시도 :

- (void)registerWithTouchDispatcher 
{ 
    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate: 
      self priority:0 swallowsTouches:YES]; 
} 

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
    return YES; 
} 

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event 
{ 

    CGPoint touchLocation = [self convertTouchToNodeSpace:touch]; 

    NSLog(@"touch end ==%f-----%f",touchLocation.x,touchLocation.y); 

    // Save old location to NSuserDefault And get new From Above 

} 

지금 아래로 위치에 따라 회전

여기
float angle = -CC_RADIANS_TO_DEGREES(atan2(playerNewPos.y-playerPos.y, playerNewPos.x-playerPos.x)); 
id action=[CCRotateTo actionWithDuration:1.0 angle:angle]; 
[player runAction:[CCEaseInOut actionWithAction:action rate:3]] 
+0

@ 빅토르 렉싱턴에 대한 감사 밖으로 지적했다. –

0

아래로 구약과 새로운 터치 위치를 얻을 수

int offX = (CurrentTouch.x - OldTouch.x); 
int offY = (CurrentTouch.y - OldTouch.y)); 

float angleRadians = atanf((float)offX/(float)offY); 
float angleDegrees = CC_RADIANS_TO_DEGREES(angleRadians); 

id action=[CCRotateTo actionWithDuration:1.0 angle:angleDegrees]; 
[player runAction:action]; 
관련 문제