Im using Consolas font to display player score. The screen is 480 wide and i want it to be in the middle. The size is 24 so to place it in the middle, shouldn’t i do:
string score = “9999”;
middle = 480/2 – (score.Lenght*24)/2;
Some how the text is too much to the left (big numbers) or too much to the right (low numbers).
I though I could calulate this since consolas is a monospaced font?
You’re better off using this:
http://msdn.microsoft.com/en-us/library/6xe5hazb%28v=vs.110%29.aspx
Or for xna:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritefont.measurestring.aspx
You can use it to measure exactly how many pixels wide the string will be when you draw it.