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:
However, after moving my camera over just a bit, it magically goes back to how it is supposed to appear:
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 j.DynamicInvoke(spriteBatch) Next DynamicInjectionList.Clear() spriteBatch.End()
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 Next Next Next
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
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
Integerso this shouldn't be a problem right?)