學習
引擎類別
ImageButton

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡



API 參考
屬性
HoverImage
平行讀取
功能: UI
ImageButton.HoverImage:ContentId

HoverImageContent
平行讀取
功能: UI
ImageButton.HoverImageContent:Content

Image
平行讀取
功能: UI
ImageButton.Image:ContentId
範例程式碼
圖像懸停鎖定
local imageLabel = script.Parent
-- 此範例中的圖像為 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- 解鎖的鎖頭 (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- 深綠色
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- 鎖定的鎖頭 (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- 深紅色
end
-- 連接事件;我們的默認狀態 是鎖定
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()

ImageColor3
平行讀取
功能: UI
ImageButton.ImageColor3:Color3
範例程式碼
圖像懸停鎖定
local imageLabel = script.Parent
-- 此範例中的圖像為 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- 解鎖的鎖頭 (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- 深綠色
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- 鎖定的鎖頭 (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- 深紅色
end
-- 連接事件;我們的默認狀態 是鎖定
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()

ImageContent
平行讀取
功能: UI
ImageButton.ImageContent:Content

ImageRectOffset
平行讀取
功能: UI
ImageButton.ImageRectOffset:Vector2
範例程式碼
使用精靈表的影像動畫
-- 將此放置在尺寸為 256x256 的 ImageLabel/ImageButton 中
local imageLabel = script.Parent
-- 以下影像為 1024x1024,包含 12 幀 (256x256)
-- 這些幀播放一個男人出拳的動畫
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- 顯示幀的順序 (從左到右,然後從上到下)
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),
}
-- 在迴圈中一次顯示一幀動畫
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end

ImageRectSize
平行讀取
功能: UI
ImageButton.ImageRectSize:Vector2
範例程式碼
使用精靈表的影像動畫
-- 將此放置在尺寸為 256x256 的 ImageLabel/ImageButton 中
local imageLabel = script.Parent
-- 以下影像為 1024x1024,包含 12 幀 (256x256)
-- 這些幀播放一個男人出拳的動畫
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- 顯示幀的順序 (從左到右,然後從上到下)
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),
}
-- 在迴圈中一次顯示一幀動畫
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end

ImageTransparency
平行讀取
功能: UI
ImageButton.ImageTransparency:number

IsLoaded
唯讀
未複製
平行讀取
功能: UI
ImageButton.IsLoaded:boolean
範例程式碼
圖像加載時間
local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- 等待圖像加載
while not imageLabel.IsLoaded do
task.wait()
end
-- 測量並顯示加載所需的時間
local deltaTime = workspace.DistributedGameTime - startTime
print(("圖像加載時間為 %.3f 秒"):format(deltaTime))

PressedImage
平行讀取
功能: UI
ImageButton.PressedImage:ContentId

PressedImageContent
平行讀取
功能: UI
ImageButton.PressedImageContent:Content

ResampleMode
平行讀取
功能: UI
ImageButton.ResampleMode:Enum.ResamplerMode

ScaleType
平行讀取
功能: UI
ImageButton.ScaleType:Enum.ScaleType

SliceCenter
平行讀取
功能: UI
ImageButton.SliceCenter:Rect

SliceScale
平行讀取
功能: UI
ImageButton.SliceScale:number

TileSize
平行讀取
功能: UI
ImageButton.TileSize:UDim2

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。