iPhone游戏编程:tilemap黑线问题

发布于 2024-12-02 00:48:58 字数 1429 浏览 1 评论 0原文

当我在 iPhone 上运行我的应用程序(而不是在模拟器上)时,只有当我开始移动地图时才会出现奇怪的黑线。这是我移动瓦片地图的代码:

- (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]];            

    }     
}

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 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]];            

    }     
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩一世无双 2024-12-09 00:48:58

由于浮点舍入问题,累积增量会产生伪影。通过将图块放置在空间中的固定位置,并使用仿射变换移动所有内容,您将获得更好的结果。中间的解决方案是累积单个绝对偏移量并将其添加到每个图块的起始位置(显然您必须将每个起始位置缓存在某处)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文