閃光是幾種粒子發射類別之一。像其他類似粒子發射器一樣,火花對象在與父級(例如,一個>或在此父級內的一個>中)或在此父級內的一個>相關時發射粒子。與 ParticleEmitter 類比,閃光缺乏許多不同的自訂屬性和特殊方法,例如 ParticleEmitter.Lifetime 或 ParticleEmitter:Emit() 。在有限時間內創建快速特效有用;如果需要更詳細的工作,則建議使用 ParticleEmitter 來取代。
當 Sparkles.Enabled 被切換關閉時,這個對象發出的粒子將繼續渲染,直到它們的生命週期到期。當閃光物件的 Instance.Parent 設為 nil (和/或 Instance:Destroy() 編輯)時,所有粒子將立即消失。如果這個效果不是想要的,請試著將父對象隱藏在遠處的位置,然後使用 Debris 在幾秒鐘後移除閃光,讓最後一些粒子有機會過期。此對象沒有 ParticleEmitter:Clear() 方法,但可以將 Instance.Parent 設置為 nil 並返回到相同效果的對象。
閃光粒子只從BasePart中心發射到他們的父輩。將閃光對象轉換為 Attachment 而不是允許父母化閃光粒子的起始位置的自訂。
範例程式碼
The code sample below gives any new players sparkles that are colored the same as their torso color.
local Players = game:GetService("Players")
local function onCharacterSpawned(character)
local hrp = character:WaitForChild("HumanoidRootPart")
-- Add sparkles that are colored to the player's torso color
local sparkles = Instance.new("Sparkles")
sparkles.Parent = hrp
sparkles.SparkleColor = character:WaitForChild("Body Colors").TorsoColor.Color
sparkles.Enabled = true
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterSpawned)
end
Players.PlayerAdded:Connect(onPlayerAdded)
概要
屬性
決定閃光粒子的顏色。
決定是否發出閃光。
決定閃光粒子的顏色。
屬性
Color
顏色屬性決定了 Sparkles 對象所發射的所有粒子的顏色 (既有粒子和未來粒子)。它的行為類似於 ParticleEmitter.Color , 除了它只有一個顏色而不是 ColorSequence 。閃光有一個自然的顏色順序應用,當此屬性設為白色時最為明顯;閃光非常微弱地在淺綠色和紅色之間動畫。
應注意,閃光有部分 ParticleEmitter.LightEmission 效果,因此黑暗顏色傾向於更透明,白色顏色看起來非常亮。
範例程式碼
The code sample below gives any new players sparkles that are colored the same as their torso color.
local Players = game:GetService("Players")
local function onCharacterSpawned(character)
local hrp = character:WaitForChild("HumanoidRootPart")
-- Add sparkles that are colored to the player's torso color
local sparkles = Instance.new("Sparkles")
sparkles.Parent = hrp
sparkles.SparkleColor = character:WaitForChild("Body Colors").TorsoColor.Color
sparkles.Enabled = true
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterSpawned)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Enabled
啟用屬性,像 ParticleEmitter.Enabled 一樣,決定是否發射閃光粒子。任何已發射的粒子將繼續渲染直到其生命時間到期為止。此屬性有助於在稍後需要時將預製的閃光效果保持關閉。閃光粒子在 Sparkle 對物件的 Instance.Parent 設置為 nil 時被摧毀,因此此屬性有助於允許現有粒子在摧毀火焰對象之前有機會過期。請參閱下面的功能。
local Debris = game:GetService("Debris")
local part = script.Parent
function stopSparkling(sparkles)
sparkles.Enabled = false -- No more new particles
Debris:AddItem(sparkles, 4) -- Remove the object after a delay (after existing particles have expired)
end
stopSparkling(part.Sparkles)
範例程式碼
The code sample below gives any new players sparkles that are colored the same as their torso color.
local Players = game:GetService("Players")
local function onCharacterSpawned(character)
local hrp = character:WaitForChild("HumanoidRootPart")
-- Add sparkles that are colored to the player's torso color
local sparkles = Instance.new("Sparkles")
sparkles.Parent = hrp
sparkles.SparkleColor = character:WaitForChild("Body Colors").TorsoColor.Color
sparkles.Enabled = true
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterSpawned)
end
Players.PlayerAdded:Connect(onPlayerAdded)
LocalTransparencyModifier
SparkleColor
此屬性功能與 Sparkles.Color 相同。
閃光顏色屬性決定了所有由 Sparkles 對象發射的粒子的顏色(既存的粒子和未來的粒子)。它的行為類似於 ParticleEmitter.Color , 除了它只有一個顏色而不是 ColorSequence 。閃光有一個自然的顏色順序應用,當此屬性設為白色時最為明顯;閃光非常微弱地在淺綠色和紅色之間動畫。
應注意,閃光有部分 ParticleEmitter.LightEmission 效果,因此黑暗顏色傾向於更透明,白色顏色看起來非常亮。
範例程式碼
The code sample below gives any new players sparkles that are colored the same as their torso color.
local Players = game:GetService("Players")
local function onCharacterSpawned(character)
local hrp = character:WaitForChild("HumanoidRootPart")
-- Add sparkles that are colored to the player's torso color
local sparkles = Instance.new("Sparkles")
sparkles.Parent = hrp
sparkles.SparkleColor = character:WaitForChild("Body Colors").TorsoColor.Color
sparkles.Enabled = true
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterSpawned)
end
Players.PlayerAdded:Connect(onPlayerAdded)