0

我正在尝试使用 cocos2d 2.1 和 Tiled 0.9.1 制作基于 tilemap 的游戏。游戏在模拟器上完美运行,但在设备上运行时,瓷砖之间存在间隙(伪影线)。

请看截图。

瓷砖地图之间的差距

差异是原始图块(直接取自图块集的 png)与 cocos2d 渲染的图块之间的差异(在 Photoshop 中制作)。如您所见,在模拟器中它们是 100% 相同的。然而,在设备上,cocos2d 似乎将瓷砖纹理垂直缩小了一点点。1像素的条纹实际上是tileset中麻烦的tile上面的纹理。

知道是什么原因造成的以及如何解决吗?

4

2 回答 2

2

虽然使用这个答案在我的情况下启用CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL是不够的。

我还将以下代码添加到AppDelegate::applicationDidFinishLaunching()函数中,并将传递给setPosition(x, y)函数的值舍入到最接近的 int。

Director::getInstance()->setProjection(Director::Projection::_2D);

我用cocos2d-x 3.4.

于 2015-02-20T15:33:26.717 回答
0

Not certain why this happens on devices only, but you should read in ccConfig.h for parameter CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL. This in itself is a bad kludge, but it gives you a hint as to where to look.

Basically, you should make certain that all your positions are on an exact pixel boundary, ie on non-retina devices cast them to int, and on retina devices round to the nearest exact multiple of .5. Best way to ensure that is to make all your textures w,h even numbers ... the onus is on the artist for anything that will not move. If you move things, and the final position is calculated (for example in a ccTouches move,end), make certain you do this rounding there. Beware of batch nodes : the node itself, and all its children should be on pel boundary.

于 2013-11-04T12:49:03.167 回答