maybe anyone already figured that out or has an idea:
If I use a Bitmap font of a true type text I get letters with variable length:
I would like to know if there is a way to get the length of the complete object from beginning of the first letter to the end of the last letter.
a simple fixedLength * len(string) would’t do it as there is no fixed length.
I’m not sure, but here’s a basic idea - keep a dictionary of how wide each letter is. For example, all letters but i, j, l, and f are pretty much the same size, so you probably can step through the string to determine the total length according to the dictionary.
If you use the BLF module, not only do you get anti-aliased true type fonts, but you can also get the size of a given string with blf. dimensions(fontid, “string”), which will return the height and width the given string will have with the given fontid. Unfortunately, blf can be a little weird to use in the BGE (raw OpenGL calls need to be used to line up matrices). I have a blf demo somewhere on these boards if you want to hunt them down. If you’re doing GUIs, I’d take a look at BGUI . It makes GUIs in the BGE a lot easier. The downside to BGUI is that it’s still new and thus the API can be unstable (subject to change).
but that is not the plan I have right now. I still go with 2.49 and try with the available resources.
I just discovered that bitmap font characters can be wider than the single plane (e.g. character ‘w’) while ‘i’ is quite short. I might need to go with Joemans16’s idea of storing a width estimation dictionary.