iphone game programming : tilemap black lines problem
when i run my app on my iphone (not on simulator), strange black lines appears only when i start moving the map. So here is my code for moving the tilem开发者_如何学Cap :
- (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]];
}
}
Accumulating deltas will produce artifacts due to floating-point rounding issues. You'll get better results by placing tiles at a fixed location in space, and moving everything with an affine transform. An in-between solution is to accumulate a single absolute offset and adding it to the starting position of each tile (you'll obviously have to cache each start position somewhere).
精彩评论