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