Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a top down XNA game. The maps are created by tiles. A problem I recently noticed is a 'grid' of lines between the tiles. It only shows up sometimes and only depending on the camera position. I let XNA handle the positioning, why are these lines showing up?

Here is a picture with the lines:

enter image description here

However, after moving my camera over just a bit, it magically goes back to how it is supposed to appear:

enter image description here

Thanks for any help!


This is the best I can do for source code, this is an extremely large project and the rendering is done it multiple areas:

Main Render Loop For dynamic elements such as tiles:

    spriteBatch.Begin(SpriteSortMode.Deferred, Nothing, SamplerState.LinearClamp, Nothing, Nothing, Nothing, Matrix.CreateTranslation(CameraX, CameraY, 0))
    Mode.Render(spriteBatch, False)
    For Each j As [Delegate] In DynamicInjectionList


For x As Integer = 0 To GRIDMAX - 1
    For y As Integer = 0 To GRIDMAX - 1
        For z As Integer = 0 To 2
            Dim ter As TiledTerrain = Terrain(x, y, z)
            If ter IsNot Nothing Then
                sb.Draw(CBaseClient.TextureLibrary("TileMap"), New Rectangle(x * GRIDSIZE, y * GRIDSIZE, GRIDSIZE, GRIDSIZE), New Rectangle(ter.Texture_X, ter.Texture_Y, GRIDSIZE, GRIDSIZE), Color.White)
            End If

TiledTerrain.vb Class:

Imports ProtoBuf

<ProtoContract()> _
Public Class TiledTerrain

    <ProtoMember(1)> _
    Public Property X As Integer
    <ProtoMember(2)> _
    Public Property Y As Integer
    <ProtoMember(3)> _
    Public Property Z As Integer

    <ProtoMember(4)> _
    Public Property Texture_X As Integer
    <ProtoMember(5)> _
    Public Property Texture_Y As Integer

End Class

My Research:

I've done some searching into it and this is was I've found:

  • This problem is called tearing (I believe?)
  • It is commonly caused by using a floating point data type to hold the tile position (I'm using Integer so this shouldn't be a problem right?)
share|improve this question
How do you draw your tiles? Paste your drawing code and all other relevant code, we seriously need more information :) Problem could possibly have something to do with rounding errors/precision. – flai Mar 7 '12 at 1:32
@JaakkoLipsanen, There, I've added some code :) – Xander Lamkins Mar 7 '12 at 1:39
There was just recently a question on a similar topic that may be worth reading too. – Andrew Russell Mar 7 '12 at 3:49
up vote 18 down vote accepted

I assume that although your tile positions are defined in integers, your camera position may not be. So if you are trying to render pixel-perfect positions from a non-pixel-perfect position then the sampling may be off and cause lines between the tiles. In your SpriteBatch.Draw calls, I would suggesting changing the SamplerState to PointClamp to ensure that the textures are sampled on a point basis and it should remove those extra lines.

Your code revised:

    Matrix.CreateTranslation(CameraX, CameraY, 0))
share|improve this answer
Wow, worked perfectly! Thanks a ton :) – Xander Lamkins Mar 7 '12 at 10:55

I had a similar problem with DirectX 11 and this worked for me:

I changed the texture address mode in the sampler state description. Texture address mode is used to control what Direct3D does with texture coordinates outside of the range (in DirectX 11, this is [0.0f, 1.0f]). I changed the ADDRESS_U, ADDRESS_V, ADDRESS_W members to D3D11_TEXTURE_ADDRESS_CLAMP which clamps out-of-range values of texture coordinates into the range.

If there is an analogous parameter in your code than this might help.

share|improve this answer

I had a similar problem with lines showing up between my tiles too, but changing the sampler state to Point Clamp did not fix the problem.

Instead I found that turning off multi-sampling and synchronizing the vertical trace fixed the problem. This is in XNA 4.0:

public GraphicsDeviceManager _graphics;

_graphics = new GraphicsDeviceManager(this);
_graphics.PreferMultiSampling = false;
_graphics.SynchronizeWithVerticalRetrace = true;

Hope this helps someone out there!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.