Decal

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

裝飾物對象是一個對 BasePart 面應用圖像的對象。

裝飾如何工作?

裝飾將會將圖像應用到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.

Changing Decal Texture

-- 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

概要

屬性

屬性 繼承自 FaceInstance

屬性

Color3

平行讀取

Color3 染色 Decal .

開發人員應注意,此屬性只設置貼花的顏色,而不是顏色。這意味著,除非與 Decal 相關的圖像原本是白色 (RGB = 1,1,1),否則無法使用此屬性自由變更顏色。

通過減少 Color3 在聯集盟中的RGB屬性,開發人員可以使裝飾更暗。

範例程式碼

This code sample creates a Decal in the workspace and changes its Decal.Color3 property on a loop using TweenService.

Decal Color3

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

當 LocalTransparencyModified 設為 1 時,Decal將無論原本透明度如何都完全隱形。當設為 0 時,貼花的渲染透明度將與 Decal.Transparency 值匹配。這個方式的公式是:


Displayed Transparency = Transparency + ((1 - Transparency) * LocalTransparencyModifier)

注意,此屬性應僅用於客戶端,並不會複製到服務伺服器。

對於此特性的變體 BaseParts ,請參閱 BasePart.LocalTransparencyModifier

Texture

ContentId
平行讀取

Decal 應用的圖像的內容ID。

我如何上傳裝飾?

圖像可以上傳到 Roblox,只要遵守社群指南即可。有關上傳圖像的資訊,請參閱紋理和裝飾

如何查找我查找裝飾內容ID?

SoundAnimation 對象不同,裝飾品的內容ID與URL中的數字不同。有兩種主要方法可找到裝飾的內容ID:

  • 在 Roblox Studio 中將 URL 貼到紋理屬性中。Roblox 會自動將屬性更新到正確的內容 ID。請注意,此操作只能在 Roblox Studio 中執行,無法從腳本或遊戲運行時執行。
  • 將貼花插入遊戲,這通常通過「我的貼花」下的工具箱來完成。內容ID可以在插入的貼花中找到。注意,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.

Changing Decal Texture

-- 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.

Fading Decal

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 決定在同一 FaceBasePart 上渲染裝飾的順序。裝飾品會在 上升順序 中渲染,其中低值會先渲染。因此,ZIndex 更高的貼花稍後(並且位於)其他 ZIndex 更低的貼花。

有效值範圍為 -MAX_INT 到 MAX_INT,包括(2,147,483,647 或(2^31 - 1))。如果您不確定未來是否需要在兩個已存在的裝飾之間堆疊裝飾,那麼使用 100 倍數可能是一個好主意,即0, 100, 200.這樣可以確保您可以使用的 ZIndex 值大幅差異,用於在其他元素之間渲染的元素。

也見:

方法

活動