GuiBase2d

Afficher les obsolètes
Création impossible
Non navigable

GuiBase2d is an abstract class inherited by 2D GUI Objects.

Résumé

Propriétés

Évènements

Propriétés

AbsolutePosition

Lecture uniquement
Non répliqué

AbsolutePosition is a read-only property that provides the screen position of a UI element in pixels. This represents the actual pixel position at which an element renders as a result of its ancestors' sizes and positions. The GuiObject.AnchorPoint also influences the AbsolutePosition. This property, GuiBase2d.AbsoluteSize and GuiBase2d.AbsoluteRotation are a group of properties that all describe the final rendered orientation of a UI element.

For example, on a 1920 by 1080 screen, a Frame with position {0.5, 0}, {0.5, 0} would have an AbsolutePosition of (960, 540). If you were to place another Frame with position {0, 50}, {0, 50} inside that one, its AbsolutePosition would be (1010, 590). This example assumes each Frame has the default GuiObject.AnchorPoint of (0, 0), the top left corner.

Échantillons de code

Copycat Frame

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent
-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")
-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(0.5, 0.5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White
-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0)
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation
-- Insert into ancestor ScreenGui
copycat.Parent = screenGui

AbsoluteRotation

Lecture uniquement
Non répliqué

AbsoluteRotation is a read-only property that describes the actual screen rotation of a UI element, in degrees. This property, GuiBase2d.AbsoluteSize and GuiBase2d.AbsolutePosition are a group of properties that all describe the final rendered orientation of a UI element. It composes (sums) each of the UI element's ancestors' GuiObject.Rotation into one value. It does not perform bounds checking, so its value may not be in the range 0 ≤ x < 360 degrees.

For example, if FrameA has a rotation of 40 degrees, and FrameB within it has a GuiObject.Rotation of 50 degrees, then FrameB's AbsoluteRotation would be 90 degrees.

Échantillons de code

Copycat Frame

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent
-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")
-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(0.5, 0.5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White
-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0)
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation
-- Insert into ancestor ScreenGui
copycat.Parent = screenGui

AbsoluteSize

Lecture uniquement
Non répliqué

AbsoluteSize is a read-only property that provides the screen size of a UI element in pixels. This represents the actual pixel size at which an element renders as a result of its ancestors' sizes. This property, GuiBase2d.AbsolutePosition and GuiBase2d.AbsoluteRotation are a group of properties that all describe the final rendered orientation of a UI element.

For example, on a 1920 by 1080 screen, if FrameA exists within FrameB, and they both have a Size of {.5, 0}, {.5, 0}, then the AbsoluteSize of FrameA (the inner frame) would be (480, 270) as the GuiObject.Size property determines the size of a child UI element relative to its parent. Both of the frames are set to 50% of the parent size. Since 50% of 50% is 25%, and 25% of our screen size, 1920 by 1080, is (480, 270), this would be the resultant AbsoluteSize of the inner frame.

Échantillons de code

Copycat Frame

-- Place within a Frame, TextLabel, etc.
local guiObject = script.Parent
-- For this object to be rendered, it must be a descendant of a ScreenGui
local screenGui = guiObject:FindFirstAncestorOfClass("ScreenGui")
-- Create a copy
local copycat = Instance.new("Frame")
copycat.BackgroundTransparency = 0.5
copycat.BackgroundColor3 = Color3.new(0.5, 0.5, 1) -- Light blue
copycat.BorderColor3 = Color3.new(1, 1, 1) -- White
-- Orient the copy just as the original; do so "absolutely"
copycat.AnchorPoint = Vector2.new(0, 0)
copycat.Position = UDim2.new(0, guiObject.AbsolutePosition.X, 0, guiObject.AbsolutePosition.Y)
copycat.Size = UDim2.new(0, guiObject.AbsoluteSize.X, 0, guiObject.AbsoluteSize.Y)
copycat.Rotation = guiObject.AbsoluteRotation
-- Insert into ancestor ScreenGui
copycat.Parent = screenGui

AutoLocalize

Lecture parallèle

When set to true, localization will be applied to this GuiBase2d and its descendants. The entries used for localization are the same set of entries returned by LocalizationService:GetTableEntries(). Entries with GuiBase2d.AutoLocalize enabled are automatically re-translated after the cloud table loads if necessary.

See also GuiBase2d.RootLocalizationTable.

RootLocalizationTable

Lecture parallèle

A reference to a LocalizationTable to be used to apply automated localization to this GuiBase2d and its descendants.

The GuiBase2d.AutoLocalize property must be set to true on this object and its ancestors for automated localization to be applied. You can set this to reference a LocalizationTable anywhere in the DataModel. It is not required to be a child of LocalizationService. When RootLocalizationTable is set on a GUI object, then that object and all of its children will try to use that specific LocalizationTable and its ancestors for automatic text replacement before using the tables under LocalizationService in an undefined order and the cloud table.

If there is no translation available in the referenced table it will look for a translation in the parent of that table, if it is also a LocalizationTable, and so on.

See also LocalizationService:GetTableEntries() which explains how the GuiBase2d.RootLocalizationTable is used for automated localization.

SelectionBehaviorDown

Lecture parallèle

Customizes gamepad selection behavior in the down direction.

SelectionBehaviorLeft

Lecture parallèle

Customizes gamepad selection behavior in the left direction.

SelectionBehaviorRight

Lecture parallèle

Customizes gamepad selection behavior in the right direction.

SelectionBehaviorUp

Lecture parallèle

Customizes gamepad selection behavior in the up direction.

SelectionGroup

Lecture parallèle

Toggling SelectionGroup on for a GUI allows customization of how gamepad selection can move between buttons, which are descendants of the SelectionGroup, leaves the group, and selects other buttons. Setting SelectionGroup to true exposes the SelectionBehaviorUp/Down/Left/ Right properties, which can be set to Enum.SelectionBehavior.Escape or Enum.SelectionBehavior.Stop. Escape is the default behavior. When set to Escape, the gamepad selection tries to first find a selection within the SelectionGroup and only moves outside if it does not find a suitable button. When set to Stop, gamepad selection only looks within the SelectionGroup and does not move outside of the group from the SelectionBehavior direction.

Méthodes

Évènements

SelectionChanged

This event fires when the selection changes within any descendants of the connected GuiBase2d. When the selection highlight moves to a GuiObject, the event bubbles from that GuiObject to all of its ancestors, informing them that the selection has changed/entered/exited to a GuiObject in their descendant tree.

Paramètres

amISelected: bool

True if the new selection matches the attached GuiBase2d.

previousSelection: GuiObject
newSelection: GuiObject

Échantillons de code

SelectionChanged Background Color

local backgroundWindow = script.Parent.BackgroundWindow
local function selectionChanged(isSelfSelected, previousSelection, newSelection)
if newSelection and newSelection:IsDescendantOf(backgroundWindow) then
backgroundWindow.BackgroundColor3 = Color3.new(0, 1, 0)
else
backgroundWindow.BackgroundColor3 = Color3.new(1, 0, 0)
end
end
backgroundWindow.SelectionChanged:Connect(selectionChanged)