Hello, I’m making a platformer in pixel art and I have some issue with displaying some sprite.
Sometime, the rectangle display a bit of the to sprite above it.
I create a tiny project just for see if the bug was on my platformer game, so I create a new monogame for window project and here is the program :
Texture2D sprite;
Rectangle rectangle;
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
sprite = Content.Load<Texture2D>("player");
rectangle = new Rectangle(0, 32, 32, 32);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
//spriteBatch.Begin(samplerState: SamplerState.PointClamp);
spriteBatch.Draw(sprite,new Vector2(50,50), rectangle, Color.White, 0, Vector2.Zero, new Vector2(12), 0, 0);
spriteBatch.End();
base.Draw(gameTime);
}
Here you can see the render…
…and here is the sprite that I use (in png, it 32*32 pixels) :
Normally when the game display the sprite with the rectangle (I took the first frame of the walk animation), we are not supposed to see the foot of the sprite just above (the first sprite of the base animation) :
However this is just the tiny project, and in my platformer project, I use the “spriteBatch.Begin(samplerState: SamplerState.PointClamp);” for keep all pixels intact, and I have the same issue, I still see sometime a bit of the sprite above.
I try to re-create this situation in the tiny project by using “spriteBatch.Begin(samplerState: SamplerState.PointClamp);” instead of a normal “spriteBatch.Begin();” but I did not manage to do it. (I also try to use float like 10.5f for the size of the sprite in the spriteBatch.Draw() method ).
Note : in my platformer project I use a matrix to render sprite, but I don’t think that impact the fact to have a portion of the sprite above.
To avoid this, I can do a margin of 1 pixel between each frame, but I prefer to avoid using a margin, I will use them only if I don’t find any solution.