最近遇到個問題,在用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