概要
屬性
HoverImage:ContentId |
Image:ContentId |
PressedImage:ContentId |
API 參考
屬性
HoverImage
ImageButton.HoverImage:ContentId
Image
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
範例程式碼
圖像懸停鎖定
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()ImageRectOffset
範例程式碼
使用精靈表的影像動畫
-- 將此放置在尺寸為 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
endImageRectSize
範例程式碼
使用精靈表的影像動畫
-- 將此放置在尺寸為 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
endIsLoaded
範例程式碼
圖像加載時間
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
ImageButton.PressedImage:ContentId