エンジンクラス
ImageButton
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
プロパティ
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),
}
-- フレームを一度に1つずつループしてアニメート
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),
}
-- フレームを一度に1つずつループしてアニメート
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