ImageButton

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

ImageButton ทำงานเหมือนกับ ImageLabel ในเรื่องการเรนเดอร์ด้วยพฤติกรรมเพิ่มเติมของ GuiButton มันจะกำหนดคุณสมบัติการเรนเดอร์ภาพเดียวกับที่ Class.ImageLabel ทำ

คุณสามารถปิดการรวมภาพโดยการตั้ง ImageButton.ImageTransparency เป็น 1 หนึ่งรูปสี่เหลี่ยมที่สามารถใช้เป็นปุ่มได้ อย่างไรก็ตาม อาจเป็นการดีกว่าที่จะใช้ TextButton ที่ว่างเปล่าส

ตัวอย่างโค้ด

This code sample gives custom colors to an ImageButton of a backpack while it is hovered and pressed.

ImageButton Press Color

-- Place this code in a LocalScript in an ImageButton
local imageButton = script.Parent
local colorNormal = Color3.new(1, 1, 1) -- white
local colorHover = Color3.new(0, 1, 0) -- green
local colorPress = Color3.new(1, 0, 0) -- red
-- This is a 32x32 image of a backpack
imageButton.Image = "rbxassetid://787458668"
imageButton.BackgroundTransparency = 1
local function onActivated()
print("open the inventory")
end
local function onPressed()
imageButton.ImageColor3 = colorPress
end
local function onReleased()
imageButton.ImageColor3 = colorHover
end
local function onEntered()
imageButton.ImageColor3 = colorHover
end
local function onLeft()
imageButton.ImageColor3 = colorNormal
end
imageButton.MouseEnter:Connect(onEntered)
imageButton.MouseLeave:Connect(onLeft)
imageButton.MouseButton1Down:Connect(onPressed)
imageButton.MouseButton1Up:Connect(onReleased)
imageButton.Activated:Connect(onActivated)
-- Start with the default, non-hovered state
onLeft()

สรุป

คุณสมบัติ

  • HoverImage:ContentId
    อ่านพร้อมๆ กัน

    รหัสเนื้อผ้าที่จะใช้เมื่อ ImageButton ถูกเลื่อน.

  • Image:ContentId
    อ่านพร้อมๆ กัน

    เนื้อหาของภาพที่แสดงโดยส่วนหนึ่งของ UI Reads and writes to ImageContent .

  • อ่านพร้อมๆ กัน

    กำหนดวิธีการที่ภาพที่เรนเดอร์จะสี

  • ซ่อนอยู่
    อ่านพร้อมๆ กัน

    เนื้อหาของภาพที่แสดงโดยส่วนประกอบ UI รองรับ รหัส URIs สินทรัพย์ และ EditableImage

  • อ่านพร้อมๆ กัน

    ค่าเลือกออกในพิกเซลของพื้นที่ย่อของรูปภาพที่จะแสดง

  • อ่านพร้อมๆ กัน

    กำหนดขนาดในพิกเซลของพื้นที่ย่อของรูปภาพที่จะแสดง

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของรูปภาพที่เรนเดอร์

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ระบุว่าภาพสร้างเสร็จจากเว็บไซต์ Roblox หรือไม่

  • PressedImage:ContentId
    อ่านพร้อมๆ กัน

    TextureId ที่จะใช้เมื่อ ImageButton กด

  • อ่านพร้อมๆ กัน

    เลือกโหมดการปรับแต่งรูปภาพสำหรับปุ่ม

  • อ่านพร้อมๆ กัน

    กำหนดวิธีที่รูปภาพจะปรับใหญ่หรือเล็กตามขนาดของรูปภาพที่แสดงในรายการ UI

  • อ่านพร้อมๆ กัน

    ตั้งค่าขอบของชิ้นส่วนของรูปภาพ 9 ชิ้น

  • อ่านพร้อมๆ กัน

    ปรับขนาดขอบ 9 ด้านโดยอัตราส่วนที่กำหนด

  • อ่านพร้อมๆ กัน

    ตั้งค่าขนาดของกระเบื้องของ ImageButton

คุณสมบัติรับทอดมาจากGuiButton
  • อ่านพร้อมๆ กัน

    กำหนดว่าปุ่มมีสีเมื่อเมาส์เลื่อนผ่านหรือคลิกปุ่มนั้น

  • อ่านพร้อมๆ กัน

    หากเป็นเช่นนั้นเมื่อรูปแบบ GUI ปรากฏขึ้นจะไม่มีการล็อคเมาส์จนกว่าปุ่มเมาส์ขวาจะลง

  • อ่านพร้อมๆ กัน

    ตัวแปรบูลีนที่ระบุว่ามีการเลือกตัวอักษรหรือไม่

  • อ่านพร้อมๆ กัน

    ตั้งค่าสไตล์ของ GuiButton ตามรายการสไตล์ล่วงหน้า

คุณสมบัติรับทอดมาจากGuiObject
  • อ่านพร้อมๆ กัน

    กำหนดว่ารูปแบบนี้สามารถรับข้อมูลการป้อนของผู้ใช้ได้หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดจุดเริ่มต้นของ GuiObject สัมพันธ์กับขนาดอันตามตัวเลข

  • อ่านพร้อมๆ กัน

    กำหนดว่าจะมีการปรับขนาดหรือไม่ขึ้นอยู่กับเนื้อหาของลูก

  • อ่านพร้อมๆ กัน

    กำหนดสีพื้นหลัง GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดความโปร่งใสของพื้นหลังและขอบเขตของ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดสีของขอบ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดวิธีการที่ GuiObject ขอบเขตถูกวางโดยเฉลี่ยกับขนาดของมัน

  • อ่านพร้อมๆ กัน

    กำหนดความกว้างของพิกเซลของ GuiObject รอบ

  • อ่านพร้อมๆ กัน

    กำหนดว่าควรเรนเดอร์หรือไม่ GuiObjects ภายนอกขอบเขตของรูปปั้น GUI ระดับพ่อของคุณ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดว่าผู้เล่นกดเมาส์บน GuiObject หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดว่า GuiButton สามารถใช้งานได้หรือไม่ หรือว่า GuiState ของ GuiObject กําลังเปลี่ยนแปลงหรือไม่

  • อ่านพร้อมๆ กัน

    ควบคุมลำดับการเรียงลำดับของ GuiObject เมื่อใช้กับ UIGridStyleLayout

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะได้รับการเลือกเมื่อเครื่องยนต์ผู้ควบคุมเลื่อนลง

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนซ้าย

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนไปทางขวา

  • อ่านพร้อมๆ กัน

    ตั้งค่า GuiObject ซึ่งจะถูกเลือกเมื่อเครื่องยนต์เลื่อนขึ้น

  • อ่านพร้อมๆ กัน

    กำหนดตำแหน่งพิกเซลและตำแหน่งเศษเส้นของ GuiObject

  • อ่านพร้อมๆ กัน

    กำหนดจำนวนองศาที่ GuiObject หมุน

  • อ่านพร้อมๆ กัน

    กำหนดว่า GUI สามารถเลือกได้โดย gamepad หรือไม่

  • อ่านพร้อมๆ กัน

    เปลี่ยนแปลงการตกแต่งการเลือกที่ใช้สำหรับแพดพันเกม

  • อ่านพร้อมๆ กัน

    ลำดับของ GuiObjects ที่เลือกโดย UI เกมแพด.

  • อ่านพร้อมๆ กัน

    กำหนดขนาดพิกเซลและขนาดพิกเซลของ GuiObject

  • อ่านพร้อมๆ กัน

    ตั้งค่า Size แกนที่ Class.GuiObject จะสร้างบน, สัมพันธ์กับขนาดของพ่อของมัน.

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
    เลิกใช้แล้ว

    สมบัติสัมพันธ์ผสมของ BackgroundTransparency และ TextTransparency

  • อ่านพร้อมๆ กัน

    กำหนดว่า GuiObject และบุตรหลานของมันจะถูกเรนเดอร์หรือไม่

  • อ่านพร้อมๆ กัน

    กำหนดลำดับที่เรนเดอร์ GuiObject เมื่อเป็นคู่กับคนอื่น

คุณสมบัติรับทอดมาจากGuiBase2d
  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายตำแหน่งหน้าจอที่เป็นไปเลยของรายการ UI ในพิกเซล

  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายการหมุนเวียนหน้าจริงของ UI โดยองศา

  • อ่านอย่างเดียว
    ไม่ซ้ำ

    อธิบายขนาดหน้าจอที่เป็นไปจริงของรายการ UI

  • อ่านพร้อมๆ กัน

    เมื่อตั้งค่าเป็น true จะใช้การแปลภาษาใน GuiBase2d และลูกหลานของมัน

  • อ่านพร้อมๆ กัน

    การอ้างอิงถึง LocalizationTable ที่จะใช้ในการประยุกต์การแปลอัตโนมัติสู่ GuiBase2d และลูกหลานของมัน

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักในแนวลง

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพานเกมในแนวโน้มทางซ้าย

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักเกมในทิศทางที่ถูกต้อง

  • อ่านพร้อมๆ กัน

    ปรับแต่งพฤติกรรมการเลือกแพดพักในแนวตั้งขึ้น

  • อ่านพร้อมๆ กัน

    ช่วยให้คุณสามารถปรับแต่งการเคลื่อนไหวของแผงควบคุมเกม

วิธีการ

วิธีการรับทอดมาจากGuiObject

อีเวนต์

อีเวนต์รับทอดมาจากGuiButtonอีเวนต์รับทอดมาจากGuiObject
  • เกิดขึ้นเมื่อผู้ใช้เริ่มต้นใช้งานผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มคีย์บอร์ดลง, ฯลฯ)

  • ไฟร์เมื่อผู้ใช้เปลี่ยนวิธีการโต้ตอบผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มกล้อง, ฯลฯ)

  • ไฟร์เมื่อผู้ใช้หยุดใช้งานผ่านอุปกรณ์ระหว่างมนุษย์-คอมพิวเตอร์ (ปุ่มเมาส์ลง, แตะเริ่ม, ปุ่มคีย์บอร์ดลง, ฯลฯ)

  • จะเกิดขึ้นเมื่อผู้ใช้ย้ายเมาส์ไปที่องค์ประกอบ GUI

  • จะเกิดขึ้นเมื่อผู้ใช้ย้ายเมาส์ออกจากส่วน GUI

  • การเพิ่มเติมเมื่อผู้ใช้เคลื่อนเมาส์ไปยัง GUI เมื่ออยู่ภายในส่วนหนึ่งของ GUI

  • จะเกิดขึ้นเมื่อผู้ใช้เลื่อนเมาส์กลับเมื่อเมาส์อยู่เหนือ GUI เอเจนต์

  • จะเกิดขึ้นเมื่อผู้ใช้เลื่อนเมาส์ไปข้างหน้าเมื่อเมาส์อยู่เหนือรายการ GUI

  • จุดเกิดเหตุเมื่อ GuiObject ได้รับการโฟกัสด้วย Gamepad ตัวเลือก

  • ไฟร์เมื่อ Gamepad เลือกเปลี่ยนโฟกัสไปที่ GuiObject

  • เกิดขึ้นเมื่อผู้เล่นเริ่มต้น ดำเนินการต่อและหยุดการกด UI เป็นเวลานาน

  • TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นยกนิ้วของพวกเขาบนองค์ประกอบ UI

  • TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal

    เปิดเมื่อผู้เล่นทำการเลื่อนหรือดึงด้วยนิ้วสองนิ้วบน UI

  • TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการหมุนโดยใช้นิ้วสองนิ้วบนรูปปั้น

  • TouchSwipe(swipeDirection : Enum.SwipeDirection,numberOfTouches : number):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการเลื่อนสไนเปอร์บนองค์ประกอบ UI

  • TouchTap(touchPositions : Array):RBXScriptSignal

    เกิดขึ้นเมื่อผู้เล่นทำการเลื่อนสายตาในส่วน UI

อีเวนต์รับทอดมาจากGuiBase2d
  • SelectionChanged(amISelected : bool,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal

    เกิดขึ้นเมื่อเลือกแผงควบคุมเกมเคลื่อนไปยัง, ออกหรือเปลี่ยนแปลงใน GuiBase2d หรือ GuiObjects ต้นได้

คุณสมบัติ

HoverImage

ContentId
อ่านพร้อมๆ กัน

รหัสเนื้อผ้าที่จะใช้เมื่อ ImageButton ถูกเลื่อน.

Image

ContentId
อ่านพร้อมๆ กัน

RobloxID สินทรัพย์ของของหวานหรือรูปภาพที่อัปโหลดไปยังเว็บไ

ตัวอย่างโค้ด

This code sample causes an ImageLabel/ImageButton to display a red padlock. When the mouse is hovered, it changes to a green unlocked padlock.

Image Hover Lock

local imageLabel = script.Parent
-- The images in this example are 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Unlocked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Dark green
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Locked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Dark red
end
-- Connect events; our default state is locked
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()

ImageColor3

อ่านพร้อมๆ กัน

สมบัติทรัพย์ของสีของรูปภาพ กำหนดวิธีการสีของรูปภาพ เมื่อตั้งค่าไว้ที่สีขาว จะไม่มีการสีของรูปภาพ โปรไฟน์นี้มีประโยชน์มากสำหรับการใช้รูปภาพเก่า: หากต้นไม้ที่เป็นสีขาวสมบูรณ

ตัวอย่างโค้ด

This code sample causes an ImageLabel/ImageButton to display a red padlock. When the mouse is hovered, it changes to a green unlocked padlock.

Image Hover Lock

local imageLabel = script.Parent
-- The images in this example are 64x64
imageLabel.Size = UDim2.new(0, 64, 0, 64)
local function unlock()
imageLabel.Image = "rbxassetid://284402785" -- Unlocked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0, 0.5, 0) -- Dark green
end
local function lock()
imageLabel.Image = "rbxassetid://284402752" -- Locked padlock (64x64)
imageLabel.ImageColor3 = Color3.new(0.5, 0, 0) -- Dark red
end
-- Connect events; our default state is locked
imageLabel.MouseEnter:Connect(unlock)
imageLabel.MouseLeave:Connect(lock)
lock()

This code sample loops an ImageLabel or ImageButton's ImageColor3 through the entire rainbow using RunService's RenderStepped.

Rainbow Image

local RunService = game:GetService("RunService")
local imageLabel = script.Parent
local function onRenderStep()
imageLabel.ImageColor3 = Color3.fromHSV(workspace.DistributedGameTime / 8 % 1, 1, 1)
end
RunService.RenderStepped:Connect(onRenderStep)

ImageContent

ซ่อนอยู่
อ่านพร้อมๆ กัน

สมบัตินี้ควรรองรับ รหัสสินค้า หรืออ้างอิงถึงวัตถุ EditableImage

รหัสสินทรัพย์สามารถอ้างถึงภาพหรือข้อความที่อัปโหลดไปยัง Roblox ได้ มันทำงานได้เหมือนกันกับ Decal.Texture เกี่ยวกับการโหลดภาพ

รูปภาพที่เรนเดอร์จะถูกสีขึ้นโดยใช้ ImageButton.ImageColor3 ตัว สามารถทำให้รูปภาพเรนเดอร์เป็นลายพราง ขนาดเครื่องมือการเรียบเรียง หรือ 9-sliced โดยปรับปรุงสมบัติสมบัติ

ImageRectOffset

อ่านพร้อมๆ กัน

ช่วยให้การแสดงผลส่วนหนึ่งของรูปภาพในความร่วมกับ ImageButton.ImageRectSize นี้ สมบัตินี้กำหนดค่าเครื่องคิดเลขออกจากด้านบนซ้ายของพื้นที่รูปภาพที่จะแสดง

สมบัตินี้จะทำงานได้เช่นเดียวกับ ImageLabel.ImageRectSize

ตัวอย่างโค้ด

This code sample uses ImageRectOffset/ImageRectSize in order to play an animation of a man throwing a punch

Image Animation using Spritesheet

-- Place this in an ImageLabel/ImageButton with size 256x256
local imageLabel = script.Parent
-- The following image is 1024x1024 with 12 frames (256x256)
-- The frames play an animation of a man throwing a punch
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- The order of the frames to be displayed (left-to-right, then top-to-bottom)
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),
}
-- Animate the frames one at a time in a loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end

This code sample demonstrates the different ScaleType options - Stretch, Tile and Slice. It does this by resizing an ImageLabel/ImageButton in a circle.

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

ImageRectSize

อ่านพร้อมๆ กัน

ช่วยให้การแสดงผลส่วนหนึ่งของรูปภาพร่วมกับ ImageButton.ImageRectOffset นี้ สมบัตินี้จะกำหนดขนาดของพิกเซลของพื้นที่รูปภาพที่จะปรากฏ หากมีมิติใด ๆ ตั้งค่าไว้ 0 จะแสดงรูปภาพทั้งหมดแทน

สมบัตินี้จะทำงานได้เช่นเดียวกับ ImageLabel.ImageRectOffset

ตัวอย่างโค้ด

This code sample uses ImageRectOffset/ImageRectSize in order to play an animation of a man throwing a punch

Image Animation using Spritesheet

-- Place this in an ImageLabel/ImageButton with size 256x256
local imageLabel = script.Parent
-- The following image is 1024x1024 with 12 frames (256x256)
-- The frames play an animation of a man throwing a punch
imageLabel.Image = "rbxassetid://848623155"
imageLabel.ImageRectSize = Vector2.new(256, 256)
-- The order of the frames to be displayed (left-to-right, then top-to-bottom)
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),
}
-- Animate the frames one at a time in a loop
while true do
for _, frame in ipairs(frames) do
imageLabel.ImageRectOffset = frame * imageLabel.ImageRectSize
task.wait(0.1)
end
end

This code sample demonstrates the different ScaleType options - Stretch, Tile and Slice. It does this by resizing an ImageLabel/ImageButton in a circle.

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

ImageTransparency

อ่านพร้อมๆ กัน

ความโปร่งใสของรูปภาพสร้างขึ้นโดย UI ระบุค่าของ 0 เป็นสีเงาสมบูรณ์ และค่าของ 1 เป็นสีเงาสมบูรณ์ (ในทางมองเห็น) นี้สมบูรณ์เป็นปกติ คุณสมบัตินี้จะทำงานเช่นเด

ตัวอย่างโค้ด

This code sample oscillates the ImageTransparency of an ImageLabel/ImageButton from 0 to 1 using a sine wave.

Oscillate ImageTransparency

local RunService = game:GetService("RunService")
local imageLabel = script.Parent
local function onRenderStep()
-- Oscillate ImageTransparency from 0 to 1 using a sine wave
imageLabel.ImageTransparency = math.sin(workspace.DistributedGameTime * math.pi) * 0.5 + 0.5
end
RunService.RenderStepped:Connect(onRenderStep)

IsLoaded

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัติคุณสมบัติ IsLoaded ระบุว่า หาก ImageButton.Image สมบัติคุณสมบัติโหลดจากเว็บไซต์ Roblox เสร็จสิ้น รูปภาพที่ปฏิเสธการโมเดอร์จะไม่โหลด

ตัวอย่างโค้ด

This code sample measures how long an ImageLabel or ImageButton takes to load an image. If the image was already loaded, this will be 0.

Image Load Time

local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- Wait for the image to load
while not imageLabel.IsLoaded do
task.wait()
end
-- Measure and display how long it took to load
local deltaTime = workspace.DistributedGameTime - startTime
print(("Image loaded in %.3f seconds"):format(deltaTime))

PressedImage

ContentId
อ่านพร้อมๆ กัน

รหัสเนื้อผ้าที่สามารถตั้งค่าเป็นสมบัติสัญลักษณ์ ImageButton เมื่อปุ่มถูกกด มันจะเรนเดอร์รูปภาพนี้

ResampleMode

อ่านพร้อมๆ กัน

กำหนดวิธีที่รูปภาพดูเมื่อมันถูกขนาดตั้ง

โดยปกติฉากจะลดความละเอียดของเนื้อหาเมื่อแสดงใหญ่หรือเล็กกว่าขนาดของมันในหน่วยความจำของเนื้อหา ในขณะที่ Enum.ResamplerMode.Pixelated เก็บรักษาขอบเฉียบของเนื้อหา

อ่านพร้อมๆ กัน

สมบัตินี้ประกอบด้วย Class.ImageButton.Image ที่เป็นรูปสัญลักษณ์ สมบัตินี้ประกอบด้วย Class.ImageButton.Image ที่เป็นรูปสัญลักษณ์

โดยปกติ, สมบัตินี้คือ Enum.ScaleType.Stretch ซึ่งจะเพียงแค่ยืด/แนบขนาดของรูปภาพให้เหมาะกับพื้นที่ของรูปภาพ UI เท่านั้น เนื่องจากพิกเซลโปร่งใสต

สำหรับ Enum.ScaleType.Slice คุณสมบัติ ImageButton.SliceCenter จะปรากฏในหน้าต่าง โปรพีโพดี้ เมื่อขยายขึ้น มุมจะเป็นขนาดของไอเท็มที่เป

ในที่สุด, สําหรับ Enum.ScaleType.Tile จะมีสมบัติสมบัติของ ImageButton.TileSize ในหน้า ImageButton.TileSize นี้ สําหรับรูปแบบที่มีขนาดของแต่ละรูปแบบ

ตัวอย่างโค้ด

This code sample demonstrates the different ScaleType options - Stretch, Tile and Slice. It does this by resizing an ImageLabel/ImageButton in a circle.

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

SliceCenter

อ่านพร้อมๆ กัน

สมบูรณ์กลางเป็นสมบูรณ์กลางเมื่อ 9 สลับ รูป เมื่อ ImageButton.ScaleType ติดตั้งไว้ใน Studio ค

หากต้องการเรียนรู้เพิ่มเติมเกี่ยวกับรูปภาพ 9 สไลส์ โปรดดูที่ไททัลนี้: การออกแบบ UI 9 Slice

ตัวอย่างโค้ด

This code sample demonstrates the different ScaleType options - Stretch, Tile and Slice. It does this by resizing an ImageLabel/ImageButton in a circle.

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

SliceScale

อ่านพร้อมๆ กัน

ปรับขนาดขอบ 9 สลับโดยอัตราส่วนที่กำหนด นี่หมายถึงว่าขอบรอบ 9 สลับจะเติบโตขึ้นเหมือนคุณอัปโหลดเวอร์ชันใหม่ของเนื้อผ้าที่เพิ่มขนาด

เป็นตัวคูณสำหรับขอบของ 9 สลัด มันเป็นประโยชน์สำหรับการใช้รูปภาพของมุมหนึ่งที่มีมุมหนึ่งเหมือนกันสำหรับหลายรัศมี

ดูเพิ่มเติม:

  • ImageButton.ScaleType กำหนดวิธีการที่รูปภาพจะปรับให้เหมาะสมถ้าปรากฏในรูปแบบ UI ที่มีขนาดแตกต่างจากรูปแบบต้นฉบับ
  • ImageLabel.ScaleCenter กำหนดตำแหน่งศูนย์กลางของรูปภาพ 9 สลับ
  • ImageButton.SliceScale คือคุณสมบัติเดียวกันในด้านความสามารถ แต่สำหรับ ImageButtons

TileSize

อ่านพร้อมๆ กัน

TileSize ตั้งค่าขนาดของ TileButton คือ 0, 1, 1, 0 ค่าเริ่มต้นของ TileButton คือ 1, 1, 1, 0 ส่วนประกอบของ TileButton จะเริ่มตั้งแต่มุมล่างซ้ายของรูปภ

สมบัตินี้จะไม่มีผลถ้า ScaleType สำหรับปุ่มรูปภาพติดอยู่กับกระเบื้องแทนที่จะเป็นสตรีชหรือยืด

ตัวอย่างโค้ด

This code sample demonstrates the different ScaleType options - Stretch, Tile and Slice. It does this by resizing an ImageLabel/ImageButton in a circle.

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

วิธีการ

อีเวนต์