概要
屬性
Image:ContentId |
API 參考
屬性
Image
ImageLabel.Image:ContentId
ImageTransparency
範例程式碼
振盪圖像透明度
local RunService = game:GetService("RunService")
local imageLabel =
script.Parent
local function onRenderStep()
-- 振盪圖像透明度從 0 到 1 使用正弦波
imageLabel.ImageTransparency = math.sin(workspace.DistributedGameTime
* math.pi) * 0.5 + 0.5
end
RunService.RenderStepped:Connect(onRenderStep)IsLoaded
範例程式碼
圖像加載時間
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))TileSize
範例程式碼
圖像縮放模式示範
local imageLabel = script.Parent
-- 將源圖像設置為 64x64 鎖頭圖像
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- 白色
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- 黑色
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size =
UDim2.new(0, 100 + math.cos(theta * 2 * math.pi) * 50, 0, 100 + math.sin(theta * 2 * math.pi) * 50)
task.wait()
end
end
while true do
-- 拉伸只是簡單地將源圖像拉伸以適應
-- UI 元素的空間
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- 平鋪將多次渲染源圖像
-- 以填滿 UI 元素的空間
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- 切片將圖像變成九切片 UI。
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end