Image Button
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
プロパティ
HoverImage:ContentId |
Image:ContentId |
PressedImage:ContentId |
APIリファレンス
プロパティ
Hover Image
Image Button. Hover Image:ContentId
Image
Image Button. Image:ContentId
コードサンプル
画像ホバーロック
local imageLabel = script.Parent
-- この例の画像は 64x64 です
imageLabel.Size = UDim2.fromOffset(64, 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()Image Color3
コードサンプル
画像ホバーロック
local imageLabel = script.Parent
-- この例の画像は 64x64 です
imageLabel.Size = UDim2.fromOffset(64, 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()Image Rect Offset
コードサンプル
スプライトシートを使用した画像アニメーション
-- 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),
}
-- フレームを一度に1つずつループしてアニメート
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
endImage Rect Size
コードサンプル
スプライトシートを使用した画像アニメーション
-- 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),
}
-- フレームを一度に1つずつループしてアニメート
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
endIs Loaded
コードサンプル
画像の読み込み時間
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))Pressed Image
Image Button. Pressed Image:ContentId