概要
属性
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