How to set Popup position on the screen center

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tuan

I’m making a 2D game. I don’t know how to set Popup position on screen center.
I search some tuturial on youtube but it is for portrait layout.
How to setup popup menu on the screen center for landscape layout.
Thanks you so much

:bust_in_silhouette: Reply From: njamster

Not sure what’s your issue here. There is a function for that:

:bust_in_silhouette: Reply From:

Firstly, you’ll need to set the pivot offset to 40 and 40 so it appears in the middle of the popup, this is vital as the overall position of the popup is connected to the popup, because of this offest the popup will require to have a position of (-40, -40) so that the offset position is (0, 0)
Because the center of the viewport is located at (512x, 300y) then the position of the popup will be 472x (or 512 - 40) and 260y (or 300 - 40).
Now the popup should be located in the center of the viewport.