Search code examples
c#xnamonogame

Why do some sprites stop rendering when I zoom in using a translation matrix?


I'm using Monogame to build a game and I had the camera working for a long time, I recently changed all my sprites from 64*64 to 32*32 and I'm having trouble with the camera zoom and drawing sprites (view GIF), I am using the depth property in the Spritebatch to order my sprites.

Draw method:

_spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend,
        SamplerState.PointClamp, null, null, null, camera.TranslationMatrix);

        tileMap.Draw(_spriteBatch);
        sceneObjectHandler.Draw(_spriteBatch);
        player.Draw(_spriteBatch);
_spriteBatch.End();

GIF:

What happens when I zoom

Anybody have any ideas?


Solution

  • If Anyone comes across this post in the future I found the solution:

    When creating the translation matrix for scaling the view use:

    Matrix.CreateScale(scale, scale, 1)
    

    instead of:

    Matrix.CreateScale(scale)
    

    So that the Z-index does not affect the scaling