1
\$\begingroup\$

I'm new to programming, and I finally delved into XNA/MonoGame for wanting to practice coding game logic.

I'd like to know what the difference is between a Position (Vector2) and a Destination Rectangle (Rectangle), when it comes to positioning a sprite.

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

The simple answer is: the Vector2 positions the sprite at the X,Y coordinates, while Destination rectangle fills the sprite to fit that rectangle.

More advanced answer:

Sprites are in reality quads made up of two triangles, since underneath all this graphics stuff 3D routines are used. So both Draw methods transfer the sprite to a quad. This quad is basically a rectangle.

So what the Vector2 variant does is create a DestinationRectangle internally like this when calling SpriteBatch.Draw():

destrect = new Rectangle((int)V2.X, (int)V2.Y, Texture.Width, Texture.Height);
\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the info. I noticed that the 8th overload in SpriteBatch.Draw() includes both a Vector2 and a DestinationRectangle for the same purpose--to display the position. Does that mean I must set either one of them to null? \$\endgroup\$ Commented Feb 19, 2017 at 10:55
  • 1
    \$\begingroup\$ In the overload that takes both vector2 and rectangle, the rectangle is the source rectangle. It means the sprite will be draw only using that section from the Texture. \$\endgroup\$
    – Felsir
    Commented Feb 19, 2017 at 11:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .