Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What is the best and easiest way to get the width of a String using Slick2D?

I'm working on the achievement interface menu in my game that displays some images. On each image I need to draw a string such as "Reach Level 5.". Only problem is that I don't know how to get the string width to properly center the string on the image.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The Font class is the base class for all the fonts used in Slick2D. It has a method called getWidth(string) (documentation). This function returns an integer the represents the width of the string as it would be drawn. This goes for the main two classes that extend Font

If using TrueTypeFont you can use getWidth(string), documentation.

If using UnicodeFont you can use getWidth(string), documentation.

share|improve this answer
    
Perfect! Thank you very much. Quick and detailed answer. –  mbreen May 1 '12 at 21:15
    
No problem, remember to up vote if it was useful and accept if it worked for you. And welcome to GDSE! –  Byte56 May 1 '12 at 21:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.