Need help with obsolete SpriteBatch.Draw(...) overloads

I was reading an old tutorial http://www.gamefromscratch.com/post/2015/06/19/MonoGame-Tutorial-Textures-and-SpriteBatch.aspx and I’m aware a thing has changed since, but I don’t know what to do about it, and the two topics I’ve seen here about it so far (9120 and 9313) don’t quite cut it.

For instance, this line appears in said tutorial:
spriteBatch.Draw(texture, destinationRectangle: new Rectangle(0, 0, 300, 300), origin:new Vector2(texture.Width/2,texture.Height/2), rotation:-45f );
I neither know which overloads of Draw() exist nor which are considered obsolete. What can I replace this with?

in this case use

Draw(Texture, new Rectangle(0, 0, 300, 300), new Rectangle(0, 0, texture.Width, texture.Height), Color.White, -45f, new Vector2(texture.Width / 2, texture.Height / 2), SpriteEffects.None, 0);

1 Like

I mean, yes, thank you, that answers the specific thing I was doing. However, I kind of want to understand what’s available in case this comes up again… Eh, maybe giving the internal files a second look at a time that isn’t 3 AM will work.

…Yeah sleep helps.

So, to recap, if I understand correctly, only this extremely generic version of Draw with an absurd amount of optional parameters is being deprecated because optimization suffered otherwise:
public void Draw(Texture2D texture, Vector2? position = default(Vector2?), Rectangle? destinationRectangle = default(Rectangle?), Rectangle? sourceRectangle = default(Rectangle?), Vector2? origin = default(Vector2?), float rotation = 0, Vector2? scale = default(Vector2?), Color? color = default(Color?), SpriteEffects effects = SpriteEffects.None, float layerDepth = 0);

The available overloads NOW are (, grouping similar ones with each other) (also, gross, Discourse just eats spaces at random even in preformatted text):

public void Draw(Texture2D texture, Rectangle destinationRectangle, Color color); public void Draw(Texture2D texture, Vector2 position , Color color);

public void Draw(Texture2D texture, Vector2 position , Rectangle? sourceRectangle, Color color); public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color);

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);

With no arbitrary intermediate ones. Any “extra” parameters should therefore be manually filled with defaults like Color.White, SpriteEffects.None, etc.

Thanks for your help, and I hope this helps anyone who was as confused as I was about this.

2 Likes