# 2D TileGrid image problem

I’m trying to make a tile grid where the images are 128 by 128 but for some reason when you move around you get this weird squishy Lines.

no weird squishy Lines

with weird squishy Lines

anyone know why or how to fix it?

You are probably using floats for the tiles position.

Try using ints

that dit not work

You had better post some code for us to look at then, we may see something you have missed

can it be that i use a spritesheet and use the Rectangle

``````Vector2 fred = new Vector2((int)x,(int)y);
``````

fred.X and fred.Y are floats

You cannot initialise a float with an int and be sure to get an integer value

This isn’t the correct place to explain why, but it has to do with how floats work. Floats are always approximations of numbers

For example 384 will be represented as 1.1 * 2 ^ 8 ( head maths, so forgive me if I am a bit out)

You haven’t shown your drawing code, but if you are using the vector2 it is very probably your problem.

If you are using SpriteBatch I would recommend switching to using rectangles rather than Vector2’s

i look in to the float part.
that gave me an idea maby it was the Camera.

after i add (int) to the Camera position it fix it.

So Thanks Alot m8!

There are some better explained answers around here. But basically it kicks in with your translation if you dont have a rounded integer for your camera position or zoom.

An easy fix is to clamp the camera position to an int, however this doesn’t allow for nice smooth camera movement. If your camera is following something in your game moving by vectors and your camera is moving by pixels it appears jumpy.

Also if your not running on a fixed update, rounding to int can also make your camera jumpy, as the int amount rounded to can fluctuate per frame.

This issue is here when your using a tile sheet not a full texture. When drawing there is some bleed from the surrounding pixels on your tile sheet.

What you need to do is pad your texture. So if your sprite is 128,128… put a 1 pixel padding around the outside of your tile on your tile sheet. I generally extend the outside pixel line of my tiles into the padding area.

Also as a side note. I have found drawing using a vector as an overload for the drawto location rather than a rectangle is faster. If you need to use a scale for width and height you can use a vector as a scale.

Probably not noticeable on a small map, but when drawing 20k tiles to a screen it was a noticeable fps difference.

Hey boot thanks for the information very informative.

this is how i Draw

for this school project i think this is good enough.
anyway Thanks alot for the help.