Using the tool Tiled and importing + drawing it with MonoGame.Extended.Tiled Everything works like a charm. But as soon as I adjust the view matrix, the tiles start to bleed. (Gap between the tiles)
The view matrix depends on two values:
- Position of the camera (Integer for pixel placement)
- Scale (For res. independent rendering)
I develop the game on one resolution (virtual) and just up/downscale the whole matrix. Thus, I don't need to adjust the game to several resolutions nor play with DPI stuff.
This is how I calculate the view and proj matrix.
//Get the "local" scale. This scalation depends on the virtual and actual resolution ratio.
float localScaleX = ScreenWidth / VirtualWidth;
float localScaleY = ScreenHeight / VirtualHeight;
//Don't use float position values. Only int for exact PX coordinates on the screen.
Vector2 position = new Vector2((int)TransformationComponent.Position.X,
//If the position changes, a matrix adjustment is required.
ViewMatrix = Matrix.CreateTranslation(new Vector3(-position, 0.0f)) *
Matrix.CreateTranslation(new Vector3(-Origin, 0.0f)) *
Matrix.CreateScale(localScaleX * ScaleX, localScaleY * ScaleY, 1f) *
Matrix.CreateTranslation(new Vector3(Origin, 0.0f));
//The projectMatrix also depends on scale and resolution properties.
ProjectionMatrix = Matrix.CreateOrthographicOffCenter(0, ScreenWidth, ScreenHeight, 0, 0, 1f);
This is how I draw the map
MapRenderer.Draw(Map, CameraComponent.ViewMatrix, CameraComponent.ProjectionMatrix, ShaderComponent?.Shader ?? null, 0);
If I change the Windows size (thus the scalation changes) the texture bleeding does appear or disapear. (Some scaling factors are nice, some are not) I did try to round the Scale to 4,3,2 or even 1 comma digit. But still, the bleeding is existant.
Is there anything I am missing?
Thanks for your effort and time