Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between origin and position arguments in SpriteBatch.DrawString

Tags:

c#

xna

Using C# and the XNA Framework, what is the difference between the "position" and "origin" arguments when calling the SpriteBatch.DrawString method?

like image 265
shizbiz Avatar asked Oct 23 '25 23:10

shizbiz


2 Answers

The origin is an offset related to the position.

Position is related with the upper left corner of the string.

  • If you want to rotate your string, it will rotate about that corner, but if you want to rotate about the center of the string in the given position, you have to set the origin as the half size of the string.

  • Also it lets you rotate about an arbitrary point, doing the right math with origin.

  • If you want align centered your string, you have to set origin as the half size of the string, and the string will be centered in the position.

  • If you want align right your string, your origin has to be set to the size of the string.

like image 89
Blau Avatar answered Oct 25 '25 11:10

Blau


A little old, but I thought it would be helpful for others that come across this thread while searching for this topic. This confused me as well so I put this image together to help me out...

enter image description here.

like image 42
Mikla Avatar answered Oct 25 '25 11:10

Mikla