Get character location of a BitmapText

How do i get the location (or Rectangle) of, say the 7th character, for a BitmapText object?

@KevinKostlan said: How do i get the location (or Rectangle) of, say the 7th character, for a BitmapText object?

There is no good way to do this, unfortunately. It’s one of the things I’d like to add someday if I ever get around to refactoring that hornet’s nest.

Fear not, there is a way to get the information you probably need… especially if you only have one line of text. Just ask for the length of the string up to that character and the length of the string only up to and including that character. That should give you the ‘x’ of your box.

How about calling getCharacterAdvance(char curChar, char nextChar, float size) over and over (for each character in the string)?

@KevinKostlan said: How about calling getCharacterAdvance(char curChar, char nextChar, float size) over and over (for each character in the string)?

You’d miss the kerning.

@pspeed said: You'd miss the kerning.

It doesn’t seem like I would, the source includes kerning:

[java]
public float getCharacterAdvance(char curChar, char nextChar, float size){
BitmapCharacter c = charSet.getCharacter(curChar);
if (c == null)
return 0f;
float advance = size * c.getXAdvance();
advance += c.getKerning(nextChar) * size;
return advance;
} [/java]

@KevinKostlan said: It doesn't seem like I would, the source includes kerning:

[java]
public float getCharacterAdvance(char curChar, char nextChar, float size){
BitmapCharacter c = charSet.getCharacter(curChar);
if (c == null)
return 0f;
float advance = size * c.getXAdvance();
advance += c.getKerning(nextChar) * size;
return advance;
} [/java]

Yeah, I didn’t realize it was taking both characters. You could try it, I guess.