2011-08-28 4 views
0

내 아이폰 (시뮬레이터가 아님)에서 앱을 실행할 때 이상한 검은 색 선이지도 이동을 시작할 때만 나타납니다. 타일 ​​맵 이동 코드는 다음과 같습니다.iphone 게임 프로그래밍 : tilemap 검은 선 문제

- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer { 

    if (recognizer.state == UIGestureRecognizerStateBegan) {  

     CGPoint touchLocation = [recognizer locationInView:recognizer.view]; 
     touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation]; 
     touchLocation = [self convertToNodeSpace:touchLocation];     

    } else if (recognizer.state == UIGestureRecognizerStateChanged) {  

     CGPoint translation = [recognizer translationInView:recognizer.view]; 
     translation = ccp(translation.x, -translation.y); 
     CGPoint newPos = ccpAdd(self.position, translation); 
     self.position = [self boundLayerPos:newPos]; 
     [recognizer setTranslation:CGPointZero inView:recognizer.view];  

    } else if (recognizer.state == UIGestureRecognizerStateEnded) { 

     float scrollDuration = 0.2; 
     CGPoint velocity = [recognizer velocityInView:recognizer.view]; 
     CGPoint newPos = ccpAdd(self.position, ccpMult(ccp(velocity.x, velocity.y * -1), scrollDuration)); 
     newPos = [self boundLayerPos:newPos]; 

     [self stopAllActions]; 
     CCMoveTo *moveTo = [CCMoveTo actionWithDuration:scrollDuration position:newPos];    
     [self runAction:[CCEaseOut actionWithAction:moveTo rate:1]];    

    }  
} 

답변

2

누적 델타가 부동 소수점 올림 문제로 인해 아티팩트를 생성합니다. 공간의 고정 된 위치에 타일을 배치하고 아핀 변환을 사용하여 모든 것을 이동함으로써 더 나은 결과를 얻을 수 있습니다. 중간 솔루션은 단일 절대 오프셋을 누적하여 각 타일의 시작 위치에 추가하는 것입니다 (각 시작 위치를 어딘가에 캐시해야합니다).

+0

나는 멍청하다. 나는 그 방법을 이해하지 못한다. – hugo411

+0

@ the1nz4ne : 그럼 내가 제안한 두 번째 방법을 고수하라. 각 타일의 수명이 시작된 곳을 기억하고 처음에는 0 인 오프셋 누산기를 유지하십시오. 이동 이벤트가 등록 될 때마다 이동을 누적기에 추가하고 각 타일을 원래 위치와 누적기를 더한 값으로 설정하십시오. –