SpriteBatch.Draw obsolete

I want to flip my sprite horizontally while drawing and I can’t figure out how to use the correct parameters without either an error or a warning about the method being obsolete.

This is what I assume it would be:
sb.Draw(NumbersGame.Arrow, resolutionRightArrow, Color.White, SpriteEffects.FlipHorizontally);

Except it comes up for errors for the color (cannot convert from color to rectangle) and the SpriteEffects bit (cannot convert from sprite effects to rectangle).

What is the correct way to lay out these arguments?

P.S: When I provide all the default values (says it’s obsolete): sb.Draw(NumbersGame.Arrow, resolutionRightArrow, null, null, null, 0f, null, Color.White, SpriteEffects.FlipHorizontally);

I use this kind of line
spriteBatch.Draw(Texture, pos, null, SpriteColor, Rotation, Origin, Scale, SpriteEffects.None, z);

There are a few versions you can use:

public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth);
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth);

What do I do for layerDepth? I tried -100, -1, 0, 1, and 100 and none work.

What’s wrong when you pass 0? Define what doesn’t work.

LayerDepth only works, if you use the correct Sortmode in .Begin() … correct me if I am wrong …

1 Like

Additional to what @reiti.net says:

Use float numbers to define layer depths. Here are some examples:

// 1.
spriteBatch.Begin(SpriteSortMode.BackToFront);
// ↓
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 100, 100), color: Color.White, layerDepth: 0.2f);
// ↓
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 50, 50), color: Color.Red, layerDepth: 0.1f);
// ↓
spriteBatch.End(); // Red Pixel ontop of White Pixel

// 2.
spriteBatch.Begin(SpriteSortMode.FrontToBack);
// ↑
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 100, 100), color: Color.White, layerDepth: 0.2f);
// ↑
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 50, 50), color: Color.Red, layerDepth: 0.1f);
// ↑
spriteBatch.End();// White Pixel ontop of Red Pixel

// 3.
spriteBatch.Begin(SpriteSortMode.BackToFront);
// ↓
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 100, 100), color: Color.White, layerDepth: 0.1f);
// ↓
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 50, 50), color: Color.Red, layerDepth: 0.2f);
// ↓
spriteBatch.End(); // White Pixel ontop of Red Pixel

// 4.
spriteBatch.Begin(SpriteSortMode.FrontToBack);
// ↑
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 100, 100), color: Color.White, layerDepth: 0.1f);
// ↑
spriteBatch.Draw(texture: Pixel, destinationRectangle: new Rectangle(0, 0, 50, 50), color: Color.Red, layerDepth: 0.2f);
// ↑
spriteBatch.End();// Red Pixel ontop of White Pixel