15

I have text objects in my scene that I'd like to use in the HUD for a game. When they exist as text objects, I get a different result in a viewport and in game engine once I start playing the game.

I have two separate text objects here viewport

In game engine they are shown bigger, and therefore overlap. badly shown text

But once I press alt+C and convert them to mesh, they look perfectly the same in game engine as in viewport, just as I want:

enter image description here

But I want them to exist as text objects, because i want to modify them during the game using "obj.text".

So, why are they shown differently when they are the text objects and is there a way to fix that, besides moving them around and figuring the layout out via trial and error?

Version 2.73

Edit1: Just to clarify, my problem is not only about two text objects overlapping each other. If I want to create other interface elements using mesh, they will look exactly the same in game as in viewport. But if I have both mesh and text objects, the texts will bulk up, ruining my interface layout. That's why I'm trying to make text objects look exactly the same in game as in viewport.

I could, of course, just make the text smaller and just run the game several times and adjust the size of the text by trial and error. But that's a pretty tedious workaround ;)

Highstaker
  • 723
  • 6
  • 14

4 Answers4

1

Your problem could be that the Text (your amount of ammo) is not being placed to the right of its origin as displayed in object mode, but to the left or center of it when in the game engine. I am not sure if that really is your issue. But if it is, this code should help:

obj["Text"] = obj["Text"].center((5-len(str(obj["Text"])))*5)

You might still need to specify the code to where exactly you need your center to be as this is just what worked for the purpose I used this for in my project. I hope this solves your problem if not it may still be useful somewhere else.

1

Have you thought about displaying only a single text object, and when you replace the new text and or new number string in script use a concatenated string variable which contains the single string.

I don't know Java; but, the concept would be A$="Ammo", B$=numeric $tring (Ammo Count) and DisplayText$= "a$+" :"+B$. Something like that? Then you'd only have to deal with the Font size, vs game engine Font size, and your single Text Object would be variable DisplayText$ which would look like "Ammo :0" (Of course replacing my simple variables with your own, etc.)

Like I said, I don't know Blender Script language, per se: so, don't know the string concatenator, could be the symbol "&" or semicolon ";" between the strings.

Cyberchipz
  • 613
  • 4
  • 12
  • In Python code, I believe the procedure for concatenating the two strings (to get the new, combined string, the text we want to display) would be something like: "Ammo: " + str(ammo_count_variable). I don't know which function to use to get Blender to assign that new string to the object that displays it, though. – Stan May 09 '15 at 03:23
  • Text objects have a "obj.text" parameter that is exactly that. Doing this that way is not a problem. But my problem is that the usual meshes are show exactly as in viewport, while the text objects bulk up a little bit, making the layout broken in game mode. So I'm trying to find a way to make text objects look equal in both viewport and game modes. – Highstaker May 09 '15 at 05:33
  • So, forgive me, as I'm new, so game mode is another viewport mode, which I believe it is like, and I believe when you edit, it's wysiwyg; and so it sounds like a bug. But, I know some modifiers can work in specific modes, but not others. I know if you can submit it as a bug; if you're wrong, and it's actually an implemented feature, they'll sure let you know! I wouldn't want to do this often though. I got semi-smacked on that one once simply because it's not fun to found out the hard way what a dummy I was. lol – Cyberchipz May 18 '15 at 01:40
1

Setting the origin to geometry (In object mode: 'Object>Transform>Set Origin to Geometry')for text objects helps mostly.

TheIronLad
  • 29
  • 4
1

I notice that your viewport is currently in ortho mode, have you tried changing it to perspective mode yet? Usually changing between modes make the mesh look different. Example below.

This photo is a sphere in ortho mode

Ortho mode

This shows the same sphere in perspective mode. Perspective mode

DanielCMK
  • 531
  • 1
  • 4
  • 12