Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(Easy) How would you center a any surface gui so it is exactly in the center of a block?

Asked by 5 years ago
I am working on an fps and for the attachment to work, I need to have a way where the surface GUI is exactly in the center of my scope part so that it perfectly fits with the mouse. The problem I have is that I am pretty much terrible with UI and GUI overall, so I have no clue how to do so. I'm hoping that this is possible or there is some way to know what the offset has to be depending on the size of the image. Thanks!
0
Wrong site, buddy. raid6n 2196 — 5y
0
Nope greenhamster1 180 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

The SurfaceGui itself has no visuals, it just provides you with a container to put UI elements in, and some control over the overall pixel resolution. You can easily center things by adding a Frame child to the SurfaceGui with Size of (1,0,1,0) (that's UDim2.new(1,0,1,0) in code) and Position of all zeros. This frame fills the SurfaceGui, and can be set transparent. Then, anything you want centered, you just make it a child of the Frame and set AnchorPoint to (0.5, 0.5) and Position to (0.5, 0, 0.5, 0) That's 0.5 for the Scale values, and 0 for the pixel offsets.

0
Thank you! greenhamster1 180 — 5y
0
Thank you! greenhamster1 180 — 5y
Ad

Answer this question