Tile Maps 的黑线,锯齿问题。

Tile Maps

TileMapAtlas gaps between tiles

When using TileMapAtlas the tiles will always have Anti-Aliasing active, so if you don't remove the AA before using the Atlas you'll see lines between each tile. In order to avoid this you have to remove the Anti-Aliasing from that texture.

Code for cocos2d < 0.8.0

// Aliased images

[ Texture2D saveTexParameters] ;
[ Texture2D setAliasTexParameters] ;
TileMapAtlas * tilemap = [ TileMapAtlas tileMapAtlasWithTileFile: @ "tiles.png" mapFile: @ "levelmap.tga" tileWidth: 16 tileHeight: 16 ] ;
[ Texture2D restoreTexParameters] ;

Code for 0.8.0 ⇐ cocos2d < 0.99

        TileMapAtlas *
tilemap =
 [
TileMapAtlas tileMapAtlasWithTileFile:
@
"tiles.png"
 mapFile:
@
"levelmap.tga"
 tileWidth:
16
 tileHeight:
16
]
;
// Aliased images
[ tilemap.textureAtlas.texture setAliasTexParameters] ;

Code for cocos2d >= v0.99

        CCTileMapAtlas *
tilemap =
 [
CCTileMapAtlas tileMapAtlasWithTileFile:
@
"tiles.png"
 mapFile:
@
"levelmap.tga"
 tileWidth:
16
 tileHeight:
16
]
;
// Aliased images
[ tilemap.textureAtlas.texture setAliasTexParameters] ;
TMX Tile Map Gaps/Artifacts (Cocos2d v0.8.2)

When using TMX Tile Maps, you may notice strange behaviors such as gaps or artifacts on the map. To resolve it, try the following:

  • Set 2D Projection in the Director
  • Set Alias Parameter for the Tile map (instead of Anti-Alias)
  • If you're updating the camera center/eye, try round your input to an integer instead of passing in a float
  • Disabling Render Subpixel may work as well (Found in: /cocos2d Sources/cocos2d/ccConfig.h)
Hex tiles

Quick hack to add Hex tiles (0.6.3 / 0.7)

  • Edit updateAtlasValueAt (0.7) or updateAltasValues (0.6.3) in TileMapAtlas.m to include the following
float
 offsetX =
 x *
(
 itemWidth *
0.5f +
 (
(
int
)
(
itemWidth /
 4.0f)
)
)
;
float offsetY = y * itemHeight;
 
if ( x % 2 )
{
offsetY = y * itemHeight + 0.5f * itemHeight;
}
 
vertex.bl_x = offsetX; // A - x
vertex.bl_y = offsetY; // A - y
vertex.bl_z = 0.0f; // A - z
vertex.br_x = itemWidth + offsetX; // B - x
vertex.br_y = offsetY; // B - y
vertex.br_z = 0.0f; // B - z
vertex.tl_x = offsetX; // C - x
vertex.tl_y = itemHeight + offsetY; // C - y
vertex.tl_z = 0.0f; // C - z
vertex.tr_x = itemWidth + offsetX; // D - x
vertex.tr_y = itemHeight + offsetY; // D - y
vertex.tr_z = 0.0f; // D - z

From:http://www.cocos2d-iphone.org/wiki/doku.php/tips:tilemapgaps
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值