0
當我在我的iphone上運行我的應用程序(不在模擬器上)時,只有當我開始移動地圖時纔會出現奇怪的黑線。因此,這裏是我的移動tilemap的代碼: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]];
}
}
嗯,我是一種noob我不明白如何做到這一點 – hugo411
@ the1nz4ne:然後堅持我建議的第二種方法。只需記住每個瓦片的起始位置,並保持最初爲零的偏移累加器。每次註冊移動事件時,將移動添加到累加器,並將每個貼片設置到原始位置加累加器。 –