Engine Class
ImageButton
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
คุณสมบัติ
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" -- Padlock ที่ปลดล็อคแล้ว (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- สีเขียวเข้ม
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Padlock ที่ล็อคแล้ว (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" -- Padlock ที่ปลดล็อคแล้ว (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- สีเขียวเข้ม
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Padlock ที่ล็อคแล้ว (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- สีแดงเข้ม
end
-- เชื่อมต่อเหตุการณ์; สถานะเริ่มต้นของเราคือถูกล็อค
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()ImageRectOffset
ตัวอย่างโค้ด
การแอนิเมชันภาพโดยใช้ Spritesheet
-- วางสิ่งนี้ใน ImageLabel/ImageButton ขนาด 256x256
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
ตัวอย่างโค้ด
การแอนิเมชันภาพโดยใช้ Spritesheet
-- วางสิ่งนี้ใน ImageLabel/ImageButton ขนาด 256x256
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