[SOLVED] Change spritebatch arguments without ending?

Sorry I cannot be more specific about the title, wasn’t sure what to say other than that.

When beginning a spritebatch, drawing a texture at depth 1.0, ending then doing the same at 0.1, the one at 0.1 shows first. Why would I want to do that? Well the reason is because I want to change the spritebatch arguments(ie the matrix).

I know this isn’t a problem to do with monogame, but how would I do this?(change sprite batch arguments without ending)

Any help is appreciated, a clean project(without the spritebatch arguments) is bellow:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Game6 {
public class Game1 : Game {
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    private Texture2D texture1;
    private Texture2D texture2;

    public Game1() {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    protected override void Initialize() {

        base.Initialize();
    }

    protected override void LoadContent() {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        texture1 = Content.Load<Texture2D>("texture1");
        texture2 = Content.Load<Texture2D>("texture2");

    }

    protected override void UnloadContent() {
    }

    protected override void Update(GameTime gameTime) {

        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime) {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        spriteBatch.Draw(texture2, new Rectangle(0, 0, texture2.Width, texture2.Height), new Rectangle(0, 0, texture2.Width, texture2.Height), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 1f);
        spriteBatch.End();
        spriteBatch.Begin();
        spriteBatch.Draw(texture1, new Rectangle(0, 0, texture2.Width, texture2.Height), new Rectangle(0, 0, texture2.Width, texture2.Height), Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.1f);
        spriteBatch.End();
        base.Draw(gameTime);
    }
}

}

`

spriteBatch.Begin( … ) has some options for the order or rendering. Stuff like Deferred, Immediate etc. try them out

Nope :frowning:
What I think is happening here is that when spriteBatch.End() is called it turns what was drawn into its own texture and readies it for the screen, but when Begin() is called again it creates a new template like a rendertarget and draws there instead, and once the frame is finished its layered on to the screen. Possibly? If theres no other solution I could order my gameobjects by the depth level which should fix this, I would like to find a better solution however.

You can’t change the matrix between begin/end. The matrix is applied to the effect’s projection matrix used by SpriteBatch.
So, you need to transform your Position/Depth with your matrices before calling .Draw() or preorder your textures and call Draw in the right order.

Thank you for confirming :). I will change the title to solved now.