I draw a tile map in the MonoGame project using the sprite command.
Here is the rendering code:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, CameraManager.pInstance.pFinalTransform);
foreach( TmxLayer Layer in mCurrentTileMap.Layers)
{
for (int y = 0; y < mCurrentTileMap.Height; y++)
{
for (int x = 0; x < mCurrentTileMap.Width; x++)
{
TmxLayerTile Tile = Layer.Tiles[mCurrentTileMap.Width * y + x];
int TileID = -1;
Texture2D Texture = FindTileMapTextureForTileID(Tile.Gid, out TileID);
if (TileID > 0)
{
int atlasX = TileID % (Texture.Width / TileSize);
int atlasY = TileID / (Texture.Width / TileSize);
SpriteEffects FX = SpriteEffects.None;
if (Tile.HorizontalFlip)
{
FX = SpriteEffects.FlipHorizontally;
}
SpriteBatch.Draw(Texture, new Vector2(x * TileSize, y * TileSize), new Microsoft.Xna.Framework.Rectangle(atlasX * TileSize, atlasY * TileSize, TileSize, TileSize), Color.White, 0, Vector2.Zero, 1, FX, 0);
}
}
}
}
Here is what I consider important lines of code:
SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp,
null, null, null, CameraManager.pInstance.pFinalTransform);
SpriteBatch.Draw(Texture, new Vector2(x * TileSize, y * TileSize),
new Microsoft.Xna.Framework.Rectangle(atlasX * TileSize, atlasY * TileSize, TileSize, TileSize),
Color.White, 0, Vector2.Zero, 1, FX, 0);
As you can see, I use SamplerState.PointClamp. However, when I move around the world, I sometimes see this; below some fragments you can see one line of pixels, which are the pixels below in the sprite atlas.
Click to enlarge to clearly see the problem ...
, , , (CameraManager.pInstance.pFinalTransform), . , . , ( , 10 ), .
, ?
, .
