3
\$\begingroup\$

So I looked up a tutorial on how to scale sprites in XNA and I think I have it all figured out.

The only problem is that I want to use a spriteBatch.Begin() method overload without changing anything except for the Matrix.

The only spriteBatch.Begin() method that has a Matrix as a parameter is this one:

public void Begin (
         SpriteSortMode sortMode,
         BlendState blendState,
         SamplerState samplerState,
         DepthStencilState depthStencilState,
         RasterizerState rasterizerState,
         Effect effect,
         Matrix transformMatrix
)

I don't really want to mess around with any of the parameters except to pass in my matrix. How would I do that?

\$\endgroup\$
4
\$\begingroup\$

If you simply want to scale a sprite you can do

spriteBatch.Begin();
spriteBatch.Draw(texture, position, null, Color.White, 0f, 
Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
spriteBatch.End();

or

spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, 
Matrix.CreateScale(0.5f));
spriteBatch.Draw(texture, position, Color.White);
spriteBatch.End();

Where 0.5f means 50% of the normal size of your texture. You could also use a Vector2(x,y) instead of a float, where the x would be the resize on width, and y the resize on y.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

If you are looking to use a Matrix as a camera and to scale and rotate the scene then spriteBatch.Begin() is indeed what you are looking for. Now I know it looks like a lot of parameters but you can actually assign most of them null values. For example:

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, YourMatrix);

You can find out what the SpriteSortModes do here, but Deferred is usually what you'll want. It's really worth it to familiarize yourself with the other parameters though and you can find them on the MSDN docs as well.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.