Image Button
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
คุณสมบัติ
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
ตัวอย่างโค้ด
การเคลื่อนไหวของภาพโดยใช้ 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
endImage Rect Size
ตัวอย่างโค้ด
การเคลื่อนไหวของภาพโดยใช้ 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
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