最近遇到个问题,在用tilemap制做像素风地图后,xcode模拟器运行正常,打包真机运行发现部分地图出现瓦片间有缝隙的问题,以下图:node
游戏引擎Cocos-2dx-Lua 3.10版本,地图用Tiled 0.10.2制做,试着在DesignResolutionSize下面下手,发现问题没法解决,后来查阅资料,发如今frameworks/cocos2d-x/cocos/base下,有一个名为ccConfig.h的文件,找到以下代码:xcode
/** @def CC_FIX_ARTIFACTS_BY_STRECHING_TEXE L * If enabled, the texture coordinates will be calculated by using this formula: * - texCoord.left = (rect.origin.x*2+1) / (texture.wide*2); * - texCoord.right = texCoord.left + (rect.size.width*2-2)/(texture.wide*2); * The same for bottom and top. * This formula prevents artifacts by using 99% of the texture. * The "correct" way to prevent artifacts is by using the spritesheet-artifact-fixer.py or a similar tool. * Affected nodes: * - Sprite / SpriteBatchNode and subclasses: LabelBMFont, TMXTiledMap. * - LabelAtlas. * - QuadParticleSystem. * - TileMap. * To enabled set it to 1. Disabled by default. * @since v0.99.5 */ #ifndef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL #define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 0 #endif
将其中的0改成1,即:ide
#define CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL 1
再打包就发现缝隙被压掉了,如图:this
虽然可能重合部分不太美观,但至少玩家不仔细看是不会发觉的,不像以前那样那么刺眼。至因而否有其余更好的解决方法,或许能够尝试打包贴图的时候上下左右各留出1像素的空间,我尚未尝试,目前都是无缝隙打图片的。若是还有更好的办法均可以留言讨论~code