Monogame: Sprites don't appear when using layer depth and a magnified view

Created on 18 May 2015  路  4Comments  路  Source: MonoGame/MonoGame

I've noticed that sprites don't appear when using layer depth and a magnified view. For example, the following code will result in no sprite appearing:

c# _spriteBatch.Begin(SpriteSortMode.BackToFront, transformMatrix: Matrix.CreateScale(2f)); _spriteBatch.Draw(_texture, Vector2.Zero, layerDepth: 1f); _spriteBatch.End();

However, if I change the layer depth to 0.5 or lower, then the above example will work. Specifically, the threshold for the layer depth before the sprite disappears seems to be 1 / scale.

Also note that it doesn't matter what the SpriteSortMode is set to. It still happens regardless of this value.

I've tested this on both the latest Windows DirectX and OpenGL builds with the same results.

One thing I've noticed is that in SpriteBatchItem the Z position is currently being set to the layer depth value. Forcing the Z position to 0 gets things working again, but this is obviously not the correct fix.

DirectX Help Wanted OpenGL

Most helpful comment

Hi,

this is the behaviour in XNA too. You should use Matrix.CreateScale (2,2,1); to magnify the view without affecting the Z.

All 4 comments

Hi,

this is the behaviour in XNA too. You should use Matrix.CreateScale (2,2,1); to magnify the view without affecting the Z.

@KakCAT Ahhhh.... Yes, that works! Thank you very much! :)

So while this is not really obvious that this needs to be done for 2D stuff, I assume that this is not really an issue since it matches XNA behaviour and I should close this?

I assume that this is not really an issue since it matches XNA behaviour and I should close this?

Yeah... I don't see anything we can do here to improve things. This is just a simple math mistake.

No probs, sorry about the false alarm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willmotil picture willmotil  路  5Comments

Grabiobot picture Grabiobot  路  5Comments

Legendree picture Legendree  路  3Comments

MontyHimself picture MontyHimself  路  5Comments

Jjagg picture Jjagg  路  5Comments