Hello folks, I hope you all are doing fine. I’m trying to understand why some of the
SpriteBatch.Draw overloads don’t work when I mix in a Scaling Matrix to come up with the Transform Matrix for
SpriteBatch.Begin with a scaling factor bigger than 1f (to be fair, it still works with 1.1f, but stops working after that) – I’m talking about overloads 5, 6 and 7, which I’m mostly interested in because of the layerDepth parameter. Maybe important, maybe not, all seems to work well with scaling factors lower than 1f – the problem is when the factor is bigger than 1f.
Here’s some sample code:
Matrix c = Matrix.CreateTranslation(new Vector3(-_position.X, -_position.Y, 0)); Matrix s = Matrix.CreateScale(4f); Matrix o = Matrix.CreateTranslation(new Vector3(GameSettings.ScreenProperties.WIDTH/2, GameSettings.ScreenProperties.HEIGHT/2, 0)); Matrix t = c * s * o;
Code that works, with a Draw overload different than 5/6/7, with scaling factor 4f:
spriteBatch.Begin(transformMatrix: t); spriteBatch.Draw(_texture, _position, Color.White * _alphaFactor); spriteBatch.End();
But then, when I use something like this with scale factor 4f, it won’t work (this is overload number 7):
spriteBatch.Being(transformMatrix: t); spriteBatch.Draw(_texture, _position, null, Color.White * _alphaFactor, _rotation, _anchor, _scale, SpriteEffects.None, _layerDepth); spriteBatch.End();
For this test/example,
_texture is the same for both calls to Draw. Same applies to
_rotation is 0f,
_scale is a
_layerDepth is some value that shouldn’t matter (I hope) as I’m only drawing one
Would any of you kindly help me by letting me know if that’s something I am doing wrong (and, say, it is expected that overloads 5/6/7 don’t work when using a transformMatrix with
SpriteBatch.Begin that has upscaling embedded)? Or if not, I’d also be interested in knowing other ways to parameterize
SpriteBatch so I wouldn’t need to care about using layerDepth. Since it was available – and I’m working on the camera just now – I had already written the drawing code using layerDepth, but if that doesn’t work, I’m guessing I will have to do the depth sorting myself and draw it in the right sequence. It is relevant to me because the projection I’m getting 2D art done is Axonometric 3/4 and drawing in the correct order when in front of or behind some structure matters.
I’m on Windows11, using VS2019, Monogame Version 188.8.131.521. Targets are Windows Desktop Application and UWP CoreApp (running/testing on my XBOX).
Thanks in advance for any help you can provide!