OnscreenText positioning

I have tried everything I can find to position text on the screen using OnscreenText objects. I want to have several rows of text aligned just to the right of the left edge of my window like in this picture :

Instead I get something like this where the left edges don’t line up. Note that I specified an X position of 0.7 for both object instances. Also, I tried all manners of ‘align=’ to no avail.

My code is :


from direct.gui.OnscreenText import OnscreenText

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Class name : InfoHUD
#
# Description:
#
#	Encapsulates the information display HUD.
#
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
class InfoHUD:
	def __init__(self):
		print
 		print "~~~ Creating info HUD ..."
		print

		# Setup clock display
		self.mClockDisplay = \
			OnscreenText( \
				text = 'Clock Display Text Will Go Here', \
				pos = (-0.70, -0.95), \
				scale = 0.07, \
				fg = (1,1,0,1), \
				mayChange = True
			)
		self.mMslPosDisplay = \
			OnscreenText( \
				text = 'Missile Position Display Text Will Go Here', \
				pos = (-0.70, -0.85), \
				scale = 0.07, \
				fg = (1,1,0,1), \
				mayChange = True
			)

	def timeUpdate(self,t,x,y,z) :
		s = "Clock : %7.2f" % t
		self.mClockDisplay.setText(s)
		s = "Missile : %10.4f  %10.4f  %10.4f  " % (x,y,z)
		self.mMslPosDisplay.setText(s)

Any guidance will be appreciated …

Thanks,
Paul

Add the alignment option for the OnscreenText:
align=TextNode.ALeft

To avoid TextNode errors, I had the imports:

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *

Also, to get close to the left, I had increase the X pos to -1.3
That might be something to do with the scaling.

nb

I believe (and I’m sure someone can correct me if I’m wrong) that OnscreenText creates its objects by default in aspect2d. Aspect2d actually has a coordinate measurement of (-1,1) in the vertical axis and a horizontal measurement proportional to the ratio of your window’s (or monitor’s) width to height. For 800-by-600, it’s about (-1.33,1.33).

You can measure the width and height of your window to determine the aspect2d coordinates. Alternatively, if you run the statement aspect2d.ls(), you’ll find that there are some handy default nodes that are automatically positioned at the corners and edges of the screen. Try getPos(aspect2d) on them to find the outer boundary of the screen in aspect2d coordinates.

Best of luck!
-Mark

Thanks, this did the trick :


		xOffset = -1.31
		yOffset =  0.92
		scale = 0.05
		dY = tScale *1.3

		# Setup clock display
		self.mClockDisplay = \
			OnscreenText( \
				text = 'Clock Display Text Will Go Here', \
				pos = (xOffset, yOffset-dY), \
				scale = tScale, \
				fg = (1,1,0,1), \
				mayChange = True, \
				align=TextNode.ALeft
			)
		self.mMslPosDisplay = \
			OnscreenText( \
				text = 'Missile Position Display Text Will Go Here', \
				pos = (xOffset,yOffset), \
				scale = tScale, \
				fg = (1,1,0,1), \
				mayChange = True, \
				align=TextNode.ALeft
			)

Thanks again,
Paul