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