当我在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]];
}
}
答案 0 :(得分:2)
由于浮点舍入问题,累积的增量将产生工件。通过将瓷砖放置在空间中的固定位置,并使用仿射变换移动所有内容,您将获得更好的结果。中间解决方案是累积单个绝对偏移量并将其添加到每个图块的起始位置(显然,您必须在某处缓存每个起始位置)。