煙是多個釋放粒子類別之一。像其他類型的粒子發射器一樣,煙霧對象在與父級(例如,一個 )或在此父級內的粒子發射器(例如,一個 )相關時發出粒子。與 ParticleEmitter 類別相比,煙缺乏許多不同的自訂屬性和特殊方法,例如 ParticleEmitter.Lifetime 或 ParticleEmitter:Emit() 。在有限時間內創建快速特效有用;如果需要更詳細的工作,則建議使用 ParticleEmitter 來取代。
當 Smoke.Enabled 被切換關閉時,這個對象發出的粒子將繼續渲染,直到它們的生命週期到期。當煙霧物件的 Instance.Parent 設為 nil (和/或 Instance:Destroy() 編輯) 時,所有粒子將立即消失。如果這個效果不是想要的,請試著將父對象隱藏在遠處的位置,然後使用 Debris 在幾秒鐘後移除煙霧,讓最後一些粒子有機會過期。此對象沒有 ParticleEmitter:Clear() 方法,但可以將 Instance.Parent 設置為 nil 並返回到相同效果的對象。
煙霧粒子只從BasePart中心發射到他們的父輩。將煙對象轉換為 Attachment 而不是允許父母化粒子的起始位置的自訂。
範例程式碼
This code sample adds a Smoke object to every Fire object in the Workspace. It does this by using a recursive search.
local function recurseForFire(object)
-- Check if we found a Fire object that has no Smoke
if object:IsA("Fire") and not object.Parent:FindFirstChildOfClass("Smoke") then
-- Create a smoke effect for this fire
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
smoke.Size = object.Size / 4
smoke.Parent = object.Parent
end
-- Continue search for Fire objects
for _, child in pairs(object:GetChildren()) do
recurseForFire(child)
end
end
recurseForFire(workspace)
概要
屬性
決定煙霧粒子的顏色。
決定是否吐出煙霧粒子。
決定不透明煙霧粒子的成像方式。
決定煙霧粒子的速度。
決定新發出的煙霧粒子的尺寸。
在 0 到 1 之間的值,控制粒子效果的速度。
屬性
Color
顏色屬性決定了 Smoke 對象所發射的所有粒子的顏色 (既有粒子和未來粒子)。它的行為類似於 ParticleEmitter.Color , 除了它只有一個顏色而不是 ColorSequence 。一些白色的顏色 會產生一個很好的霧效,而非常不透明的黑色顏色 可以很好地補充一個對象 。
範例程式碼
This code sample adds a Smoke object to every Fire object in the Workspace. It does this by using a recursive search.
local function recurseForFire(object)
-- Check if we found a Fire object that has no Smoke
if object:IsA("Fire") and not object.Parent:FindFirstChildOfClass("Smoke") then
-- Create a smoke effect for this fire
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
smoke.Size = object.Size / 4
smoke.Parent = object.Parent
end
-- Continue search for Fire objects
for _, child in pairs(object:GetChildren()) do
recurseForFire(child)
end
end
recurseForFire(workspace)
Enabled
啟用屬性,像 ParticleEmitter.Enabled 一樣,決定是否會發出煙霧粒子。任何已發射的粒子將繼續渲染直到其生命時間到期為止。此屬性有助於在稍後需要時將預製的煙霧效果保持關閉。因為煙霧粒子在 Smoke 物件的 Instance.Parent 設為 nil 時會被摧毀,因此此屬性有助於讓現有粒子有機會在摧毀火焰物件之前過期。請參閱下面的功能。
local Debris = game:GetService("Debris")
local part = script.Parent
function stopSmoke(smoke)
smoke.Enabled = false -- No more new particles
Debris:AddItem(smoke, 10) -- Remove the object after a delay (after existing particles have expired)
end
stopSmoke(part.Smoke)
範例程式碼
This code sample adds a Smoke object to every Fire object in the Workspace. It does this by using a recursive search.
local function recurseForFire(object)
-- Check if we found a Fire object that has no Smoke
if object:IsA("Fire") and not object.Parent:FindFirstChildOfClass("Smoke") then
-- Create a smoke effect for this fire
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
smoke.Size = object.Size / 4
smoke.Parent = object.Parent
end
-- Continue search for Fire objects
for _, child in pairs(object:GetChildren()) do
recurseForFire(child)
end
end
recurseForFire(workspace)
LocalTransparencyModifier
Opacity
不透明度決定了煙顆粒的不透明度。它必須在範圍 [0、1] 內。這個屬性在與零件的 或粒子發射器的 相比工作倒轉:值為 0 完全隱形,值為 1 完全可見。
Roblox 使用的粒子紋理部分透明,因此設置此屬性為 1 仍然會在渲染的煙霧中產生透明度。
範例程式碼
This code sample adds a Smoke object to every Fire object in the Workspace. It does this by using a recursive search.
local function recurseForFire(object)
-- Check if we found a Fire object that has no Smoke
if object:IsA("Fire") and not object.Parent:FindFirstChildOfClass("Smoke") then
-- Create a smoke effect for this fire
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
smoke.Size = object.Size / 4
smoke.Parent = object.Parent
end
-- Continue search for Fire objects
for _, child in pairs(object:GetChildren()) do
recurseForFire(child)
end
end
recurseForFire(workspace)
RiseVelocity
RiseVelocity 與 ParticleEmitter.Speed 和 Fire.Heat 相似:它決定煙霧粒子在生命期間移動的速度。它必須在[-25, 25]範圍內。負值會導致粒子在父BasePart的底部(-Y)方向發射。
當使用 Smoke 效果創建霧時,將此屬性設為 0。對於大型煙霧效果,使上升微妙(2到8)。對於煙囪和煙囪,更高的值適當。
範例程式碼
This code sample adds a Smoke object to every Fire object in the Workspace. It does this by using a recursive search.
local function recurseForFire(object)
-- Check if we found a Fire object that has no Smoke
if object:IsA("Fire") and not object.Parent:FindFirstChildOfClass("Smoke") then
-- Create a smoke effect for this fire
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
smoke.Size = object.Size / 4
smoke.Parent = object.Parent
end
-- Continue search for Fire objects
for _, child in pairs(object:GetChildren()) do
recurseForFire(child)
end
end
recurseForFire(workspace)
Size
Smoke 的尺寸屬性決定了新發射的煙霧粒子的尺寸。與 Smoke.Color 不同,此屬性不會改變現有粒子的尺寸。它必須在範圍 [0.1, 100] 內。與 ParticleEmitter.Size 不同,此屬性只是數字 (不是 NumberSequence )。也請注意,粒子的尺寸與螺柱不是 1 對 1;事實上,煙霧粒子的尺寸比螺柱大得多。在最大尺寸時,煙霧粒子可以渲染超過 200 個單位寬!
範例程式碼
This code sample adds a Smoke object to every Fire object in the Workspace. It does this by using a recursive search.
local function recurseForFire(object)
-- Check if we found a Fire object that has no Smoke
if object:IsA("Fire") and not object.Parent:FindFirstChildOfClass("Smoke") then
-- Create a smoke effect for this fire
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0, 0, 0)
smoke.Opacity = 0.15
smoke.RiseVelocity = 4
smoke.Size = object.Size / 4
smoke.Parent = object.Parent
end
-- Continue search for Fire objects
for _, child in pairs(object:GetChildren()) do
recurseForFire(child)
end
end
recurseForFire(workspace)