Decal
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
วัตถุ Decal เป็นวัตถุที่ใช้ภาพกับใบหน้าของ BasePart
การทำงานของ Decal เป็นอย่างไร?
สติกเกอร์จะใช้ภาพกับ BasePart ที่เป็นพ่อแม่พื้นที่ที่ภาพนี้ถูกใช้กับขึ้นอยู่กับคุณสมบัติ FaceInstance.Faceขนาดของรูปภาพขึ้นอยู่กับขนาดของใบหน้า ซึ่งหมายความว่าขนาดและอัตราส่วนของรูปภาพสามารถเปลี่ยนแปลงได้โดยการเปลี่ยน BasePart.Size ของพ่อแม่ของมัน
ภาพที่ใช้สติกเกอร์จะถูกกำหนดโดยคุณสมบัติ Decal.Texture ของมันสามารถอัปโหลดภาพไปยัง Roblox ได้ตราบใดที่พวกเขาปฏิบัติตามข้อกําหนดด้านชุมชน สําหรับข้อมูลเกี่ยวกับวิธีอัปโหลดภาพดูที่ เทกเจอร์และรูปภาพ
ทางเลือกสำหรับภาพวาดทดแทน
แม้ว่าภาพวาดจะมีหลากหลายการใช้งาน แต่ในบางกรณีผู้พัฒนาอาจต้องการเลือกหนึ่งในชั้นเรียนต่อไปนี้แทน
- สำหรับเทกเจอร์พื้นผิวซ้ำๆ ควรใช้วัตถุ Texture
- เพื่อใช้องค์ประกอบ GUI ต้องใช้วัตถุ SurfaceGui
- หากต้องการเปลี่ยนผลกระทบของแสงบนภาพ ควรใช้วัตถุ SurfaceGui
ตัวอย่างโค้ด
The following code will create a Part on the ground with a Decal applied to its top face. When something hits the part, such as when a player walks over it, the texture applied to the decal will change and a sound will play.
-- create part
local part = Instance.new("Part")
part.Size = Vector3.new(5, 1, 5)
part.Position = Vector3.new(0, 0.5, 0)
part.Anchored = true
part.TopSurface = Enum.SurfaceType.Smooth
part.BrickColor = BrickColor.new("Toothpaste")
-- create decal
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Top
decal.Parent = part
-- create sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxasset://sounds/uuhhh.mp3" -- oof
sound.Parent = part
-- define faces
local happyFace = "http://www.roblox.com/asset/?id=26424652"
local sadFace = "http://www.roblox.com/asset/?id=147144198"
decal.Texture = happyFace
-- touched event
local cooldown = false
part.Touched:Connect(function(hit)
if not cooldown then
if hit and hit.Parent then
cooldown = true
sound:Play()
decal.Texture = sadFace
task.wait(1)
decal.Texture = happyFace
task.wait(0.2)
cooldown = false
end
end
end)
-- add to workspace
part.Parent = workspace
สรุป
คุณสมบัติ
ทำหน้าที่เป็นตัวคูณสําหรับคุณสมบัติของเครื่องหมาย Decal.Transparency ผลกระทบจะมองเห็นได้เฉพาะกับผู้เล่นในท้องถิ่นเท่านั้น
ContentId ของภาพที่จะถูกใช้โดย Decal
กำหนดความโปร่งใสของ Decal ด้วย 0 เป็นทึบสมบูรณ์และ 1 โปร่งใสสมบูรณ์
กำหนดลำดับการเรนเดอร์เมื่อมีการกำหนดหน้าเดียวกันให้กับภาพวาดหลายภาพ
ตั้งใบหน้าของอิฐที่วัตถุปรากฏบน
คุณสมบัติ
Color3
นักพัฒนาควรทราบว่าคุณสมบัตินี้ตั้งสีของเครื่องหมายเท่านั้น ไม่ใช่สีซึ่งหมายความว่า หากรูปที่เกี่ยวข้องกับ Decal ไม่ได้เป็นสีขาวเดิม (RGB = 1,1,1) แล้วสีไม่สามารถเปลี่ยนได้อย่างอิสระโดยใช้คุณสมบัตินี้
โดยลดคุณสมบัติ RGB ของ Color3 ในสหภาพ ผู้พัฒนาสามารถทำให้ฉลากมืดขึ้น
ตัวอย่างโค้ด
This code sample creates a Decal in the workspace and changes its Decal.Color3 property on a loop using TweenService.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Size = Vector3.new(10, 10, 1)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Transparency = 1
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Front
decal.Texture = "http://www.roblox.com/asset/?id=1145367640" -- white circle
decal.Parent = part
part.Parent = workspace
local redTween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{ Color3 = Color3.new(1, 0, 0) }
)
local greenTween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{ Color3 = Color3.new(0, 1, 0) }
)
local blueTween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{ Color3 = Color3.new(0, 0, 1) }
)
while true do
redTween:Play()
redTween.Completed:Wait()
greenTween:Play()
greenTween.Completed:Wait()
blueTween:Play()
blueTween.Completed:Wait()
end
LocalTransparencyModifier
ทำหน้าที่เป็นตัวคูณสําหรับคุณสมบัติของเครื่องหมาย Decal.Transparency ผลกระทบจะปรากฏเฉพาะใน Players.LocalPlayer
คุณสมบัตินี้ควรใช้ในสถานการณ์ที่ Decal.Transparency ถูกกำหนดโดยสคริปต์อื่นประโยชน์ของ LocalTransparencyModified คือสามารถเปลี่ยนแปลงได้โดยไม่ต้องกังวลเกี่ยวกับต้นฉบับ Decal.Transparency ของ Decal
เมื่อการปรับแต่งความโปร่งใสท้องถิ่นถูกตั้งค่าเป็น 1 แล้ว Decal จะไม่สามารถมองเห็นได้เลยไม่ว่าความโปร่งใสดั้งเดิมจะเป็นอย่างไรเมื่อตั้งค่าเป็น 0 สติกเกอร์Decal.Transparencyสูตรสำหรับสิ่งนี้คือ:
Displayed Transparency = Transparency + ((1 - Transparency) * LocalTransparencyModifier)
โปรดทราบว่าคุณสมบัตินี้ควรใช้เฉพาะในไคลเอนต์เท่านั้นและจะไม่ถูกส่งไปยังเซิร์ฟเวอร์
สำหรับตัวแปรของคุณสมบัตินี้สำหรับ BaseParts , ดู BasePart.LocalTransparencyModifier .
Texture
ID เนื้อหาของภาพที่จะถูกใช้โดย Decal
ฉันจะอัปโหลดภาพวาดได้อย่างไร?
สามารถอัปโหลดภาพไปยัง Roblox ได้ตราบใดที่พวกเขาปฏิบัติตามข้อกําหนดด้านชุมชนสำหรับข้อมูลเกี่ยวกับวิธีการอัปโหลดภาพ ดู เทกเจอร์และภาพวาด
วิธีค้นหา ID เนื้อหาของภาพที่ฉันค้นหาได้อย่างไร?
ไม่เหมือนกับ Sound และ Animation วัตถุ รหัสเนื้อหาของแผ่นประกายไฟจะไม่เหมือนกับหมายเลขใน URLมีสองวิธีหลักในการค้นหา ID เนื้อหาของแผ่นประกาย:
- ใส่ URL ลงในคุณสมบัติของเทกเจอร์ใน Roblox StudioRoblox จะอัปเดตคุณสมบัติโดยอัตโนมัติเป็น ID เนื้อหาที่ถูกต้องโปรดทราบว่าสิ่งนี้ทำงานได้เฉพาะใน Roblox Studio และไม่สามารถทำได้จากสคริปต์หรือในขณะที่เกมกําลังทํางานอยู่
- ใส่สติกเกอร์ลงในเกม โดยทั่วไปจะทำผ่านกล่องเครื่องมือภายใต้ 'สติกเกอร์ของฉัน'รหัสเนื้อหาสามารถพบได้ในฉลากที่ถูกสอดเข้าไปหมายเหตุ, InsertService:LoadAsset() สามารถใช้ได้หากนักพัฒนาต้องการอัตโนมัติวิธีนี้
ตัวอย่างโค้ด
The following code will create a Part on the ground with a Decal applied to its top face. When something hits the part, such as when a player walks over it, the texture applied to the decal will change and a sound will play.
-- create part
local part = Instance.new("Part")
part.Size = Vector3.new(5, 1, 5)
part.Position = Vector3.new(0, 0.5, 0)
part.Anchored = true
part.TopSurface = Enum.SurfaceType.Smooth
part.BrickColor = BrickColor.new("Toothpaste")
-- create decal
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Top
decal.Parent = part
-- create sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxasset://sounds/uuhhh.mp3" -- oof
sound.Parent = part
-- define faces
local happyFace = "http://www.roblox.com/asset/?id=26424652"
local sadFace = "http://www.roblox.com/asset/?id=147144198"
decal.Texture = happyFace
-- touched event
local cooldown = false
part.Touched:Connect(function(hit)
if not cooldown then
if hit and hit.Parent then
cooldown = true
sound:Play()
decal.Texture = sadFace
task.wait(1)
decal.Texture = happyFace
task.wait(0.2)
cooldown = false
end
end
end)
-- add to workspace
part.Parent = workspace
TextureContent
Transparency
กำหนดความโปร่งใสของ Decal ด้วย 0 เป็นทึบสมบูรณ์และ 1 โปร่งใสสมบูรณ์
โปรดทราบ, Decals ยังเคารพความโปร่งใสของไฟล์ภาพเดิมที่อัปโหลดไปยัง Robloxซึ่งหมายความว่าความโปร่งใสสามารถเปลี่ยนแปลงได้ก่อนอัปโหลดไปยัง Roblox และโดยไม่จำเป็นต้องใช้คุณสมบัติความโปร่งใส
Decal.LocalTransparencyModifier ทำหน้าที่เป็นตัวคูณความโปร่งใสของภาพวาดและควรใช้เมื่อความโปร่งใสของภาพวาดอาจถูกเปลี่ยนแปลงโดยสคริปต์อื่นเช่นเดียวกับตัวละครผู้เล่น
สำหรับ BaseParts , ดู BasePart.Transparency .
ตัวอย่างโค้ด
The code below will create a transparent Part with a decal that will fade in and out using TweenService and Decal.Transparency.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Size = Vector3.new(10, 10, 1)
part.Position = Vector3.new(0, 5, 0)
part.Anchored = true
part.Transparency = 1
local decal = Instance.new("Decal")
decal.Face = Enum.NormalId.Front
decal.Texture = "http://www.roblox.com/asset/?id=699259085" -- roblox logo
decal.Parent = part
part.Parent = workspace
local tween = TweenService:Create(
decal,
TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true),
{ Transparency = 1 }
)
tween:Play()
ZIndex
ZIndex กำหนดลำดับที่รูปภาพบนเดียวกัน Face ของ BasePart จะถูกแสดงออกภาพวาดจะถูกแสดงในลําดับลําดับความสําคัญเพิ่มขึ้น โดยมีค่าต่ํากว่าถูกแสดงก่อนเสมอดังนั้น สติกเกอร์ที่มี ZIndex สูงกว่าจะแสดงในภายหลัง (และอยู่เหนือ) สติกเกอร์อื่นที่มี ZIndex ต่ำกว่า
ช่วงของค่าที่ถูกต้องคือ -MAX_INT ถึง MAX_INT รวมถึง (2,147,483,647 หรือ (2^31 - 1))หากคุณไม่แน่ใจว่าคุณจะต้องเลเยอร์สติกเกอร์ระหว่างสติกเกอร์ที่มีอยู่แล้วสองรายการในอนาคตหรือไม่ ก็เป็นความคิดที่ดีที่จะใช้หลายรายการของ 100 เช่น0, 100, 200.ซึ่งช่วยให้มีช่องว่างขนาดใหญ่ของค่า ZIndex ที่คุณสามารถใช้สำหรับองค์ประกอบที่เรนเดอร์ระหว่างองค์ประกอบอื่น
ดูเพิ่ม:
- GuiObject.ZIndex คุณสมบัติที่มีพฤติกรรมคล้ายกัน แต่สำหรับองค์ประกอบ GUI