SpriteBatch.Draw(~~) is obsolete

Hey, can’t find an answer to this anywhere, and the documentation doesn’t say anything about it.

I create an object of type SpriteBatch, aptly named ‘spriteBatch’, and then call the Draw() method.

// in class
Texture2D texture;
SpriteBatch spriteBatch;

// in draw
spriteBatch.Begin();
spriteBatch.Draw(texture);
spriteBatch.End();

Everything works fine, but it marks the Draw() calls I make with green and tells me it’s obsolete and can be removed in future versions. What do I use instead? SpriteBatch class docs don’t seem to have a replacement.

Use one of the other overloads of spriteBatch.Draw() like the
spriteBatch.Draw(texture, Vector2.Zero, Color.White);

All the overloads of Draw() & DrawString() has been optimized/inlined in v3.6 of MonoGame. See #5347
That particular overload you are using is an extension of MG with many default (wildcard) parameters, so it was left unoptimized because it would be insane to break it up into all the possible overload permutations.
Some people might have used it in performance sensitive code (drawing hundreds/thousands of sprites) without realizing it. That’s why it was marked obsolete. It still works for now but from now on it’s a good practise to use one of the other overloads that best fix your situation, especially on time critical code, VS intellisense can help you find the best alternative.

2 Likes

Ahh, okay I see now. Another question though, how would I not specify a colour without it giving me that? Giving it the value ‘null’ gives me it again.

Edit: Just realised as I replied that Color.White is the answer lol.

Thank you for the clarification.

1 Like