Pixel2d position

Can anyone tell me how are positions recorded in pixel2d?

See this manual page, a few paragraphs down.

But when I try to use the pixel2d position, the OnscreenText is not visible. Code:

from direct.showbase.ShowBase import ShowBase
from direct.gui.OnscreenText import OnscreenText

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        text = OnscreenText("Hello World", pos=(400, 0, 300), scale=0.07, parent=self.pixel2d) # (400, 0, 300) is the center

game = Game()
game.run()

your scale must also fit to the use of pixel2d. Currently you have 0.07, which if parented to pixel2d doesn’t mean panda units but pixels. So, just set that to 12 or something like that and you should see the text.
Also note, that in pixel2d, the Y coordinate is used for vertical placement, not Z, so pos should be (400, 300, 0)

There are a few problems that are causing your issue:

First, as noted on that manual page, “pixel2d” as dimensions that match those of the window. However, it also notes that the origin is at the top-left, and that in the vertical it runs to -height. Thus, objects by default appear at the top-left, and in order to offset them down into the viewing area one has to use negative values.

Second, a scale of 0.07 is reasonable when attaching the object to “aspect2d” or “render2d”, which operate in size-ranges close to the value of 1. However, “pixel2d” generally operates in much larger size-ranges, often in the order of hundreds–as a result, a reasonable scale for “pixel2d” is likewise much larger.

And third, as noted above, OnscreenText uses the y-coordinate, not the z-coordinate, to offset vertically. This is inconsistent with other objects, but is, I’m afraid, one of the quirks of OnscreenText.

Nope. I did what you told but still can’t be seen
My scale is 12 and the position is 400, 300, 0

Bumping for my reply, which came in just before yours, and thus may have been missed.

So you mean for OnscreenText I should use aspect2d or set the scale to 100?

no, he means, that your Y coordinate must be negative not positive. I missed the minus in my reply.

Well, something more like 100 than 0.07–the exact value depends on the size the you want it to have, of course.

Also, this bit isn’t specific to OnscreenText–it’s related to the use of “pixel2d”.

The use of y-coordinates instead of z-coordinates is specific to OnscreenText.

That too.

OK! Thanks! Will try. By the way, in a personal chat with @rdb, I asked him to change the character limit so now only 3 characters are necessary to send a message.

1 Like

Yup. The text is definitely visible at a scale of 100. Though it is too big. I think I will stick to 50 or something

1 Like

you may also be interested in my DirectGUI designer. With that you can simply drag and drop and easily change the scale.

1 Like

Will check.

1 Like

Can you tell me the command to run setup.py. I typed this:
python setup.py what should I put here?

EDIT: Also where is the DirectFolderBrowser. Python can’t find it.

If you run python setup.py and it exits successfully, you should have a new build directory with a built executable versions of the designer. Currently the setup script will only create linux builds, but you can uncomment the “win_amd64” in it to build windows binaries, if that’s your platform.

Alternatively, just run python DirectGuiDesigner.py

It is saying “no commands supplied”

It can’t find the DirectFolderBrowser.

Ah, yes, that’s a recent change which I haven’t added to the readme yet.
Just run the following to get the requirements.

pip install -r requirements.txt

Ah, and you need to add build_apps after the setup.py

It usually is bdist_apps. I didn’t see the command in setup.py. Sorry!