Question about the screen bounds

Hello there. I’m attempting to create a main menu for my game. I’ve began using Panda3D since few days ago. And I have two qeustions:
1.) I’ve seen that the final position is inconsistent, by that I mean that the button is not correctly positioned when using having a maximized window, or using a window with the default size. Is this a bug, or intended behiavour? If yes, what are the default bounds, and how should I attack a button to the 2D screen renderer?

void _attachButton(NodePath* n2d,PGButton* button,const LVector2f& pos)
{
NodePath defbutNP = n2d->attach_new_node(button);
defbutNP.set_scale(0.05);
defbutNP.set_pos(LVecBase3(pos.get_x(),0, pos.get_y()));
}

2.) Is there a way to place 2D items with pixel coordinates? Like placing a image at (0.5 * ScreenX, 0*5 * ScreenY) That would be a great workaround for my issue.

Looking forward to some answers. Thank you!

By default, the interface has the parent element aspect2d, but if you change it to pixel2d. Then you can use it exactly like this.

1 Like

I’ll try this out. Thanks for your time!

It seems now you can just make a call to get_pixel_2d to get the measurement in pixels.

https://www.panda3d.org/reference/cxx/classWindowFramework.html#ad2f2c46dd563331b3e1052e962cb8a9d

1 Like

Oh, that’s so much better! Question: Does pixel2d use the LVector2i numerical type? Does it matter if I use LVector2i or LVector2f?

Logically, it should be Int.

I’ve seen implementations with floats, taking Monogame for example…

As far as I know, you can use Float.

1 Like

I believe that one can, indeed: the space used by pixel2d is just the same as any other in Panda.

However, if you want to place things at pixel-coordinates, then integers would likely make the most sense, I think, as they would correspond to non-fractional pixels.