Skip to main content
added 29 characters in body
Source Link
ClassicThunder
  • 8.4k
  • 37
  • 49

Changing the SpriteSortMode to Immediate is faster in the cases when the overhead of creating new batches is more signifigant than the time saved by batching. If this is the case in your situation the below will be faster. While the mode is immididate you can alter the GrahpicsDevice's state and it will impact subsiquent draw calls.

    Matrix Camera_transformation = player_camera_.GetTransformation();

    
    spritebatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
        null, null, null, Camera_transformation);

    // Background - AlphaBlend
    background_.Draw(spritebatch);

    // Particles (of a player power, I want them behind him!) - Additive
    GraphicsDevice.BlendState = BlendState.Additive;
    player_.DrawParticles(spritebatch);

    // Player - Alpha Blend
    GraphicsDevice.BlendState = BlendState.AlphaBlend;
    player_.Draw(spritebatch);
    spritebatch.End();

    // Hub/Ui - Not to be influenced by the camera, but always on top
    spriteBatch.Begin(); 
    UI.Draw(spritebatch)
    spriteBatch.End();

Changing the SpriteSortMode to Immediate is faster in the cases when the overhead of creating new batches is more signifigant than the time saved by batching. If this is the case in your situation the below will be faster. While the mode is immididate you can alter the GrahpicsDevice's state and it will impact subsiquent draw calls.

    Matrix Camera_transformation = player_camera_.GetTransformation();

    
    spritebatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
        null, null, null, Camera_transformation);

    // Background - AlphaBlend
    background_.Draw(spritebatch);

    // Particles (of a player power, I want them behind him!) - Additive
    GraphicsDevice.BlendState = BlendState.Additive;
    player_.DrawParticles(spritebatch);

    // Player - Alpha Blend
    GraphicsDevice.BlendState = BlendState.AlphaBlend;
    player_.Draw(spritebatch);
    spritebatch.End();

    // Hub/Ui - Not to be influenced by the camera, but always on top
    spriteBatch.Begin(); 
    UI.Draw(spritebatch)
    spriteBatch.End();

Changing the SpriteSortMode to Immediate is faster in the cases when the overhead of creating new batches is more signifigant than the time saved by batching. If this is the case in your situation the below will be faster. While the mode is immididate you can alter the GrahpicsDevice's state and it will impact subsiquent draw calls.

    Matrix Camera_transformation = player_camera_.GetTransformation();

    
    spritebatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
        null, null, null, Camera_transformation);

    // Background - AlphaBlend
    background_.Draw(spritebatch);

    // Particles (of a player power, I want them behind him!) - Additive
    GraphicsDevice.BlendState = BlendState.Additive;
    player_.DrawParticles(spritebatch);

    // Player - Alpha Blend
    GraphicsDevice.BlendState = BlendState.AlphaBlend;
    player_.Draw(spritebatch);
    spritebatch.End();

    // Hub/Ui - Not to be influenced by the camera, but always on top
    spriteBatch.Begin()
    UI.Draw(spritebatch)
    spriteBatch.End();
Source Link
ClassicThunder
  • 8.4k
  • 37
  • 49

Changing the SpriteSortMode to Immediate is faster in the cases when the overhead of creating new batches is more signifigant than the time saved by batching. If this is the case in your situation the below will be faster. While the mode is immididate you can alter the GrahpicsDevice's state and it will impact subsiquent draw calls.

    Matrix Camera_transformation = player_camera_.GetTransformation();

    
    spritebatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
        null, null, null, Camera_transformation);

    // Background - AlphaBlend
    background_.Draw(spritebatch);

    // Particles (of a player power, I want them behind him!) - Additive
    GraphicsDevice.BlendState = BlendState.Additive;
    player_.DrawParticles(spritebatch);

    // Player - Alpha Blend
    GraphicsDevice.BlendState = BlendState.AlphaBlend;
    player_.Draw(spritebatch);
    spritebatch.End();

    // Hub/Ui - Not to be influenced by the camera, but always on top
    spriteBatch.Begin(); 
    UI.Draw(spritebatch)
    spriteBatch.End();