Kelas Engine
ImageButton
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
Rangkuman
Properti
HoverImage:ContentId |
Image:ContentId |
PressedImage:ContentId |
Referensi API
Properti
HoverImage
ImageButton.HoverImage:ContentId
Image
ImageButton.Image:ContentId
Contoh Kode
Kunci Hover Gambar
local imageLabel = script.Parent
-- Gambarnya dalam contoh ini adalah 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Gembok yang tidak terkunci (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Hijau tua
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Gembok yang terkunci (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Merah tua
end
-- Hubungkan event; status default kita adalah terkunci
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()ImageColor3
Contoh Kode
Kunci Hover Gambar
local imageLabel = script.Parent
-- Gambarnya dalam contoh ini adalah 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Gembok yang tidak terkunci (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Hijau tua
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Gembok yang terkunci (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Merah tua
end
-- Hubungkan event; status default kita adalah terkunci
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()ImageRectOffset
Contoh Kode
Animasi Gambar menggunakan Spritesheet
-- Tempatkan ini di ImageLabel/ImageButton dengan ukuran 256x256
local imageLabel = script.Parent
-- Gambar berikut adalah 1024x1024 dengan 12 frame (256x256)
-- Frame-frame ini memainkan animasi seorang pria yang sedang melemparkan pukulan
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- Urutan frame yang akan ditampilkan (dari kiri ke kanan, lalu dari atas ke bawah)
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),
}
-- Animasikan frame satu persatu dalam loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
endImageRectSize
Contoh Kode
Animasi Gambar menggunakan Spritesheet
-- Tempatkan ini di ImageLabel/ImageButton dengan ukuran 256x256
local imageLabel = script.Parent
-- Gambar berikut adalah 1024x1024 dengan 12 frame (256x256)
-- Frame-frame ini memainkan animasi seorang pria yang sedang melemparkan pukulan
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- Urutan frame yang akan ditampilkan (dari kiri ke kanan, lalu dari atas ke bawah)
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),
}
-- Animasikan frame satu persatu dalam loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
endIsLoaded
Contoh Kode
Waktu Muat Gambar
local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- Tunggu gambar untuk dimuat
while not imageLabel.IsLoaded do
task.wait()
end
-- Ukur dan tampilkan berapa lama waktu yang dibutuhkan untuk memuat
local deltaTime = workspace.DistributedGameTime - startTime
print(("Gambar dimuat dalam %.3f detik"):format(deltaTime))PressedImage
ImageButton.PressedImage:ContentId