mort8088 Just another WordPress site

28Feb/11Off

Tweaked – “Draw Horizontally Centered Text in XNA”


Originally Posted 2009

OK I was doing my usual potter around the net tonight when I found "Draw Horizontally Centered Text in XNA" and thought I have to tweak this...

 

I hate passing parameters i don't need and you should strive to avoid magic numbers so I moved the int ScreenWidth to be a local variable and pulled the required value in from the SpriteBatch with the following line :-

And as a sort of old school codey kick removed the division from the int centerXPosition calculation and replaced it with some bit shifts to bring us to

so in all my replacement method is :-

Have fun with that, and thanks to Kris Steele for the original article 😉

Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.