How to align sprite in the center

So, I have two identical 16x16 sprites. For the first sprite, the scale is 2. For the second, the scale is 1. And I noticed that the first sprite is aligned to the top-left. How can I align this sprite to the center?

spriteBatch.Draw(texture, new Vector2(100, 100), null, Color.Black, 0, default, 2, SpriteEffects.None, 0);
spriteBatch.Draw(texture, new Vector2(100, 100), null, Color.White, 0, default, 1, SpriteEffects.None, 0);

You need to set the origin argument to an 8,8 vector(this is in texel coordinates, so for a 16x16 sprite, the center is at 8,8).

This will also move the sprites up and left by 8 pixels visually, so you’ll have to move their position to account for that.

2 Likes