Decal

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

装饰对象是应用图像到 BasePart 面的对象。

装饰如何工作?

贴花将应用图像到BasePart它所属的父辈。这张图像应用到的表面取决于 FaceInstance.Face 属性。贴花的大小取决于脸部的大小,即更改父父元素的 BasePart.Size 可以改变贴花的大小和比例。

贴花应用的图像由其 Decal.Texture 属性决定。图像可以上传到 Roblox,只要它们遵守社区指南。有关上传图像的信息,请参阅纹理和装饰

图标的替代品

虽然装饰有很多应用程序,但在某些情况下,开发人员可能会选择以下类别之一。

  • 对于重复的地砖纹理,应使用 Texture 对象
  • 要应用图形用户界面元素,应使用 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

读取并联

该 的色调。

开发人员应注意,此属性仅设置贴花的颜色,而不是颜色。这意味着,除非图像与 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 被另一个脚本设置的情况下使用。LocalTransparencyModifier 的好处是,它可以不考虑原始 Decal.TransparencyDecal

当本地透明修改器设置为 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 决定在同一 的图标上渲染的顺序。装饰在 上升顺序 中渲染,其中低值首先渲染。因此,具有更高 ZIndex 的贴花稍后(并且位于)具有更低 ZIndex 的其他贴花。

有效值范围为 -MAX_INT 到 MAX_INT,包括(2,147,483,647 或(2^31 - 1))。如果你不确定未来是否需要在两个已存在的图标之间层加一张图标,那么使用 100 倍数可能是一个好主意,即0, 100, 200.这可以确保你可以使用的 ZIndex 值大于其他元素渲染之间的元素的差距。

还见:

  • GuiObject.ZIndex , 一个类似行为的属性,但用于图形用户界面元素

方法

活动