Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Image label dosent move with the size of the screen?

When i add a image in the middle of the game then i drag the screen and the image dosent go with the size it is... But if i add the image in a corner it go's with the size of the screen. I dont have any script should i add that and how should i write?

4 comments

0

If you use Scale instead of Offset it should work. Offset stays the same size on everyone's computer while scale will adjust to fit your screen. I would make a full answer but I'm not at my computer.

0

Bump

0

When will you make a full answer?

0

When will you put code to support your question?

2 answers

Hi,

Before anything, it is to be noted that this is in no means a request site but a scripting helpers site. This post should have been posted on the ROBLOX forums rather than here.

If I understand your question correctly, you have a UI element in the middle of the screen that you want to keep in the middle of the screen no matter the size of your window.

This is extremely easy to do.(Simply edit the properties of the ui).

UI's in ROBLOX work on UDIM2. UDIM2 is simular to Vector3.new and CFrame.new in the sense that if you were scripting, you'd use UDim2.new(). The UDim2 data type can be configured using the "Position" and "Size" tab in the properties of a UI element. UDim2 takes 4 arguments, so you will notice 4 numbers(values) that you can change in the properties.

The first two are for the x value and the second two are for the y value.(UI's are not 3 dimensional).

The first and third of those 4 values is known as the scale for the UI element. The scale of your screen works from 0-1. Meaning if the size of your gui was (0,0,0,0) and the position of your gui was(0.5,0,0.5,0), it would be completely centered. (It works relative to the center of your screen)

If your size is not(0,0,0,0) and you wish to center your UI when using the scale, you can use the following formula:

(1-SizeOfUI)/2

Now, the second and fourth values of UDim2 is known as the Offset. The offset is used for when you want to deal with All Things Pixelsmeaning that the size, and position will remain the same on every computer. Meaning no matter if you're screen is smaller or bigger, the size and position will always remain the same.

Most of the time, people like to use offset for things that have to be a precise size, but use scale for centering and sizing things that should be compatible with all devices.

How would you script UDim2.news? Very simple


local UIElement = script.Parent --Being the element you want to change
UIElement.Position = UDim2.new(0,.5,0,.5) --Setting position with scale
UIElement.Size = UDim2.new(0,200,0,200) --Setting the size with the offset/

Cheers! I hope this somewhat answered your question.

2 comments

0

Thanks!

0

Sorry but i dont know how to do it? Can you like make a video

To summarize what he pretty much said^, if you want a frame/textbutton/etc. to be in the center of the screen, just do this to the position: (0.5,"half of the width of the ui",0.5,"half of the length of the ui") Where it says, "half of the width/length of the ui", put the int value(number) of half of the size in each.

This discussion is preserved as it was. New answers, comments, and votes are closed.