Hi there everyone!
I’m trying to render a tile-map created with Tiled Map Editor. I’ve parsed the map file and for each tile in layer got it’s X and Y offsets in the world and texture (tileset) coordinates and then in a cycle I call for render of a texture’s part.
The map looks good at first, but as I move the camera using Camera2d helper class I get weird flickering grid between the tiles.
Probably that’s because I render tiles separately, but how do I render 'em so they won’t flicker then?
Rendering code looks like this:
_spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Camera.TransformMatrix*Matrix.CreateScale(Camera.Zoom));
_level.Draw(_spriteBatch);
_spriteBatch.End();
And here’s the code to change camera’s transform:
private void SetCameraView(GameTime gameTime, MouseState mouseState)
{
var delta = mouseState.ScrollWheelValue - _inputState.PreviousMouseState.ScrollWheelValue;
if (delta != 0)
{
Camera.Zoom += 5f*Math.Sign(delta)*(float) gameTime.ElapsedGameTime.TotalSeconds*Camera.Zoom;
}
if (mouseState.MiddleButton == ButtonState.Pressed)
{
if (_inputState.PreviousMouseState.MiddleButton == ButtonState.Released)
{
_panOrigin = mouseState.Position.ToVector2();
}
var pan = mouseState.Position.ToVector2() - _panOrigin;
var dt = (float) gameTime.ElapsedGameTime.TotalMilliseconds/1000;
Camera.TransformMatrix *= Matrix.CreateTranslation(new Vector3(pan, 0)*dt*30);
_panOrigin += pan*dt*10;
}
}
And here is how it looks.
P.S. When zoomed a little in they stop flickering and can be clearly seen.