I am currently building a little game in XNA and found something strange. I want to draw many blocks next to another (1x1x1 with a texture on the side)

enter image description here

So what happens when I do it this lines appear:

enter image description here

enter image description here

When I move the camera the lines change the position or disappear completely. I know this is because the side of the blocks are drawn but i do not know why. Does anybody of you know a solution for my problem? (removing the sides of the cube does not count)

  • \$\begingroup\$ Could you add your draw method with spriteBatch.Begin \$\endgroup\$
    – Katu
    Commented Apr 15, 2015 at 18:13
  • \$\begingroup\$ If your blocks are spatially sorted or you can, otherwise, draw them near-to-far, it's possible that altering DepthBias could alleviate the z-fighting. \$\endgroup\$
    – Jon
    Commented Apr 16, 2015 at 7:23

1 Answer 1


(removing the sides of the cube does not count)

Sorry dude, that is what you have to do if you want this to be efficient and work every time. The reason you're getting those lines is slight depth buffer inconsistencies (also known as z-fighting). The sides of the blocks are almost at exactly the same depth as the tops of the nearer blocks.

Ideally, in a block-based game, for performance you really ought to delete non-visible faces. Here's some pseudocode of how you might do it:

// Generate a mesh of a 3D grid of blocks.
Mesh GenerateMesh(Block[, , ] blocks)
    Mesh out_mesh;
    // Loop through every block.
    for x = 0 : blocks.max_x:
        for y = 0 : blocks.max_y:
            for z = 0 : blocks.max_z:
               Block block = blocks[x, y, z]; 
               // Check each face of the block
               for face = 0 : 6:
                   Block neighbor = block.GetNeighbor(face);
                   // If the neighbor doesn't exist, add the triangles
                   // from that face.
                   if (!IsOccupied(neighbor)):
   return out_mesh;
  • 1
    \$\begingroup\$ I think there's 2 problems. One is exactly this ( OP should only draw what is visible and not full cubes ) other could be ( he mentioned that those appear and disappear when camera moves ) using pixel perfect world coordinates and then floating camera coordinates causing sampling failure to cause lines. \$\endgroup\$
    – Katu
    Commented Apr 15, 2015 at 18:11
  • \$\begingroup\$ Thanks for your help :) If you want to see more from the project: gamejolt.com/games/rpg/project-final-fantasy/42398 \$\endgroup\$
    – Patrick S
    Commented Apr 16, 2015 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .