一個 ImageButton 在渲染方面與一個 ImageLabel 相似,並具有額外的 GuiButton 行為。
概要
屬性
當 ImageButton 被漂浮時會使用的紋理ID。
由 ImageButton 元素顯示的圖像內容。讀取和寫入 ImageContent 。
決定渲染圖像將如何被彩色。
介面元素顯示的圖像內容。支持資產 URI 和 EditableImage 對象。
要顯示的圖像子區域的像素偏移。
決定要顯示的圖像子區域的像素大小。
決定渲染圖像的透明度。
指示圖像是否已從 Roblox 網站完全載入。
在按下 ImageButton 時會使用的紋理ID。
選擇按鈕的圖像重新樣本模式。
決定如果在來源圖像與顯示的 UI 元素的尺寸不同的情況下,圖像會以何種方式縮放。
設置 9 片切圖像的切割邊界。
以指定比率擴展 9 片邊。
設置圖像按鈕的瓷磚尺寸。
決定按鈕在滑鼠停止或單擊時是否自動變更顏色。
一個 HapticEffect 會在 GuiButton 被掃過時播放的實例。
如果 true 在GUI元素可見時,鼠標不會被鎖定,除非右鍵按下。
一個會在 HapticEffect 按下時播放的實例,當 GuiButton 被按下時。
一個指示對象是否已被選擇的 boolean 屬性。
根據一個預定義的 сти列設置 GuiButton 的風格。
決定這個介面元素是否會沉沒輸入。
決定 GuiObject 的起始點,相對於其絕對尺寸。
決定是否基於兒童內容進行縮放。
決定 GuiObject 背景顏色。
決定 GuiObject 背景和邊框的透明度。
決定 GuiObject 邊框的顏色。
決定在哪種方式下 GuiObject 邊界被布置在其尺寸相對。
決定 GuiObject 邊框的像素寬度。
決定是否在父 GUI 元素的範圍之外成像子元素 GuiObjects 。
決定玩家的鼠標是否在 GuiObject 上被主動按下。
控制使用 GuiObject 與 UIGridStyleLayout 時的排序順序。
設置在遊戲控制器選擇器向下移動時會選擇的 GuiObject 。
設置在遊戲控制器選擇器移動到左側時會選擇的 GuiObject 。
設置在遊戲控制器選擇器移動到右側時會選擇的 GuiObject 。
設置在遊戲控制器選擇器向上移動時會選擇的 GuiObject 。
決定 GuiObject 的像素和向量位置。
決定旋轉 GuiObject 的角度數量。
確定是否可以由遊戲控制器選擇 GuiObject 。
覆蓋使用於遊戲板的預設選擇裝飾。
由遊戲控制器介面選擇所選擇的 GuiObjects 順序。
決定 GuiObject 的像素和積分尺寸。
混合屬性 BackgroundTransparency 和 TextTransparency 。
決定是否渲染 GuiObject 和其子孫。
決定 GuiObject 對其他人的相對順序進行渲染。
方法
方法 繼承自 GuiObject- TweenPosition(endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
順暢將 GUI 移動到新的 UDim2 。
- TweenSize(endSize : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
- TweenSizeAndPosition(endSize : UDim2,endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
順暢將 GUI 移動到新的尺寸和位置。
活動
活動 繼承自 GuiButton當按鈕啟用時發生火災。
當使用者的滑鼠完全點擊 GuiButton 時發生火災。
當使用者按下左滑鼠按鈕時,在 GuiButton 上發生火災。
當使用者釋放左滑鼠按鈕時,發生在 GuiButton 上。
當使用者的滑鼠完全右鍵單擊 GuiButton 時發生火災。
當使用者按下右鍵時,在 GuiButton 上按下滑鼠右鍵。
當使用者釋放右滑鼠按鈕時,發生火災 GuiButton 。
當使用者開始使用人工智慧與電腦介面裝置(例如滑鼠按鈕向下、觸摸開始、鍵盤按鈕向下等)時發射。
當使用者變更如何透過人工智慧與電腦介面裝置(滑鼠按鈕向下、觸摸開始、鍵盤按鈕向下等)進行互動時,發射時間。
當使用者停止使用人工智慧與電腦介面裝置(例如:滑鼠按鈕向下、觸摸開始、鍵盤按鈕向下等)互動時,發射。
當使用者將鼠標移到 GUI 元素時發生火災。
當使用者將鼠標移出 GUI 元素時發生火災。
在使用者移動滑鼠時,無論在哪個GUI元素內,都會發生火災。
當使用者滾動滑鼠輪時,滑鼠停在 GUI 元素上時,發生火災。
當使用者將滑鼠輪向前滾動時,發生火災,當滑鼠在 GUI 元素上時。
當使用遊戲控制器選擇器將 GuiObject 聚焦時,發射。
當遊戲控制器選擇器停止關注 GuiObject 時發射。
當玩家開始、繼續並停止長按 UI 元素時,發生火災。
- TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal
當玩家在介面元素上移動手指時發生火災。
- TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
當玩家使用介面元素上的兩個手指執行撥動或拉動動作時,發生火焰。
- TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
當玩家使用介面元素上的兩個手指執行旋轉動作時,發生火災。
當玩家在介面元素上執行滑動動作時,發生火災。
當玩家在介面元素上執行點擊動作時,發生火焰。
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
當遊戲控制器選擇移動到、離開或變更連接的 GuiBase2d 或任何子控制器 GuiObjects 時發生火災。
屬性
HoverImageContent
Image
此屬性是一種內容類型屬性,應該持有裝飾或圖像上傳到 Roblox 的資產 ID。它與 Roblox 的圖像載入相同功能,即 Decal.Texture 。渲染的圖像將使用 ImageColor3 被色化。
請注意,可以通過調整 ScaleType 屬性來將圖像渲染為瓷磚、縮放以適應或 9 切割來將圖像切割為 9 部分。
範例程式碼
This code sample causes an ImageLabel/ImageButton to display a red padlock. When the mouse is hovered, it changes to a green unlocked padlock.
local imageLabel = script.Parent
-- The images in this example are 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Unlocked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Dark green
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Locked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Dark red
end
-- Connect events; our default state is locked
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()
ImageColor3
此屬性決定圖像如何被彩色。當設為白色時,不會發生任何色化。此屬性對於重複使用圖像資產非常有用:如果來源圖像完全白色且透明,您可以一次設置圖像的整個顏色,使用此屬性。
範例程式碼
This code sample causes an ImageLabel/ImageButton to display a red padlock. When the mouse is hovered, it changes to a green unlocked padlock.
local imageLabel = script.Parent
-- The images in this example are 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Unlocked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Dark green
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Locked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Dark red
end
-- Connect events; our default state is locked
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()
ImageContent
此屬性應包含 資產 URI 或指向 EditableImage 物件象的參考。資產 URI 可以引用到 Roblox 上傳的貼花或圖像。它與載入圖像相關的功能與 Decal.Texture 相同。
渲染的圖像將使用 ImageColor3 來色化。通過調整 ScaleType 屬性來渲染圖像為瓷磚、縮放以適應或 9 切割來實現圖像渲染。
ImageRectOffset
此屬性決定要顯示的圖像區域的像素偏移(從左上角開始),可以與 ImageRectSize 一起顯示圖像的部分顯示。
範例程式碼
This code sample uses ImageRectOffset/ImageRectSize in order to play an animation of a man throwing a punch
-- Place this in an ImageLabel/ImageButton with size 256x256
local imageLabel = script.Parent
-- The following image is 1024x1024 with 12 frames (256x256)
-- The frames play an animation of a man throwing a punch
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- The order of the frames to be displayed (left-to-right, then top-to-bottom)
local frames = {
Vector2.new(0, 0),
Vector2.new(1, 0),
Vector2.new(2, 0),
Vector2.new(3, 0),
Vector2.new(0, 1),
Vector2.new(1, 1),
Vector2.new(2, 1),
Vector2.new(3, 1),
Vector2.new(0, 2),
Vector2.new(1, 2),
Vector2.new(2, 2),
Vector2.new(3, 2),
}
-- Animate the frames one at a time in a loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end
ImageRectSize
此屬性決定要顯示的圖像區域的像素大小,可以與 ImageRectOffset 一起顯示圖像的部分顯示。如果兩個維度都設為 0 ,則整個圖像會顯示。
範例程式碼
This code sample uses ImageRectOffset/ImageRectSize in order to play an animation of a man throwing a punch
-- Place this in an ImageLabel/ImageButton with size 256x256
local imageLabel = script.Parent
-- The following image is 1024x1024 with 12 frames (256x256)
-- The frames play an animation of a man throwing a punch
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- The order of the frames to be displayed (left-to-right, then top-to-bottom)
local frames = {
Vector2.new(0, 0),
Vector2.new(1, 0),
Vector2.new(2, 0),
Vector2.new(3, 0),
Vector2.new(0, 1),
Vector2.new(1, 1),
Vector2.new(2, 1),
Vector2.new(3, 1),
Vector2.new(0, 2),
Vector2.new(1, 2),
Vector2.new(2, 2),
Vector2.new(3, 2),
}
-- Animate the frames one at a time in a loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end
ImageTransparency
此屬性決定元素渲染圖像的 alpha。值 0 是完全不透明的,值 1 是完全透明的(隱形)。此特性與 GuiObject.BackgroundTransparency 或 BasePart.Transparency 相似。
如果您以設置 ImageTransparency 為 1 來禁用圖像渲染,將導致一個簡單的長方形,可用作按鈕。然而,使用空白 TextButton 可能會更好。
IsLoaded
此屬性表示 Image 屬性是否已從 Roblox 完全載入。被管理員拒絕的圖像永遠不會載入。
範例程式碼
This code sample measures how long an ImageLabel or ImageButton takes to load an image. If the image was already loaded, this will be 0.
local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- Wait for the image to load
while not imageLabel.IsLoaded do
task.wait()
end
-- Measure and display how long it took to load
local deltaTime = workspace.DistributedGameTime - startTime
print(("Image loaded in %.3f seconds"):format(deltaTime))
PressedImageContent
ResampleMode
決定縮放圖像時的外觀。預設情況下,圖像會在顯示時將紋理磨平,使紋理記憶中的紋理尺寸大於或小於紋理記憶中的紋理尺寸。相反, Enum.ResamplerMode.Pixelated 保留圖像畫素的鋒利邊緣。
ScaleType
此屬性決定在使用者介面元素的絕對尺寸與來源圖像的尺寸不同時,Image屬性以何種方式渲染時。
預設情況下,此屬性為 Enum.ScaleType.Stretch ,它會簡單地伸展/縮小圖像尺寸,以便它完全符合 UI 元素的空間。透明畫素在上傳到 Roblox 時設為黑色,透明圖像應該應用Alpha混合以避免縮放後的圖像周圍有黑色邊緣。
對於 Enum.ScaleType.Slice ,當縮放時,角落將維持原始圖像尺寸。圖像的邊緣將延伸到圖像的寬度/高度。最後,圖像的中心將伸展以填滿圖像的中心區域。要了解更多關於9片切圖像的信息,請參閱UI 9片切設計。
對於 Enum.ScaleType.Tile ,每個圖像瓷磚的大小由 TileSize 屬性決定。
SliceScale
以指定比率擴展 9 片邊。這意味著 9 片的邊緣會像你上傳了縮放的新版本的紋理一樣增長。預設為 1.0 。
作為 9 片邊緣的乘數,它對於重複使用一個圓角圖像以多個半徑有用。
請參閱ScaleType,該方法會決定如果顯示在用戶介面元素的尺寸與來源圖像不同的情況下,圖像會以何種方式縮放。
TileSize
設置從圖像左上角開始的 ImageButton 瓷磚大小。預設值 值是 ; 縮放組件的縮放將基於 的大小來縮放瓷磚,而偏移組件則位於原始像素。例如, 的比例意味著瓷磚的尺寸將是相應軸的一半。
此屬性只有在 ScaleType 屬性設為 Enum.ScaleType.Tile 時才會啟用。