Smoke
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
Asap adalah salah satu dari beberapa Kelasemisi partikel.Seperti pemancar partikel lain dari jenisnya, objek Asap memancarkan partikel saat diberi keturunan ke BasePart (seperti Part ) atau Attachment di dalam seperti BasePart .Dibandingkan dengan kelas ParticleEmitter , Asap kurang memiliki banyak properti kustomisasi berbeda dan metode khusus, seperti ParticleEmitter.Lifetime atau ParticleEmitter:Emit().Berguna untuk membuat efek khusus cepat dalam sekejap; untuk pekerjaan yang lebih terperinci, lebih baik menggunakan ParticleEmitter alih.
Ketika Smoke.Enabled dimatikan, partikel yang dipancarkan oleh objek ini akan terus ditampilkan sampai masa hidupnya berakhir.Ketika objek Asap Instance.Parent diatur ke nil (dan/atau Instance:Destroy() diedit), semua partikel akan langsung menghilang.Jika efek ini tidak diinginkan, coba sembunyikan objek orang tua di posisi jauh, lalu hapus Asap setelah beberapa detik menggunakan Debris untuk memberi kesempatan kepada partikel terakhir untuk kedaluwarsa.Objek ini tidak memiliki metode ParticleEmitter:Clear() , tetapi mungkin untuk mengatur Instance.Parent ke nil dan kembali ke objek yang sama persis untuk efek yang sama.
Partikel asap hanya dipancarkan dari pusat BasePart ke mana mereka berasal.Membesarkan objek Asap ke Attachment sebagai gantinya memungkinkan kustomisasi posisi awal partikel.
Contoh Kode
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)
Rangkuman
Properti
Menentukan warna partikel asap.
Menentukan apakah partikel asap dipancarkan.
Menentukan bagaimana partikel asap yang tidak transpar terrender.
Menentukan kecepatan partikel asap.
Menentukan ukuran partikel asap baru yang dikeluarkan.
Nilai antara 0-1 yang mengontrol kecepatan efek partikel.
Properti
Color
Properti Warna menentukan warna semua partikel yang dipancarkan oleh objek Smoke (baik partikel yang ada maupun masa depan).Ia berperilaku serupa dengan ParticleEmitter.Color , kecuali bahwa hanya satu warna dan bukan ColorSequence .Warna putih dengan beberapa Smoke.Opacity membuat efek kabut yang bagus, dan warna hitam yang sangat tidak transparan dapat melengkapi objek Fire dengan baik.
Contoh Kode
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
Properti Aktif, seperti ParticleEmitter.Enabled, menentukan apakah partikel asap dilepaskan.Setiap partikel yang sudah dipancarkan akan terus menyajikan sampai masa hidupnya berakhir.Properti ini berguna untuk menjaga efek asap pra-dibuat sampai mereka dibutuhkan nanti.Karena partikel asap hancur ketika objek Smoke dari Instance.Parent diatur ke nil , properti ini berguna dalam memungkinkan partikel yang ada kesempatan untuk kedaluwarsa sebelum menghapus objek Api sama sekali.Lihat fungsi di bawah ini.
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)
Contoh Kode
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
Opakitas menentukan opakitas partikel asap.Ini harus berada dalam rentang [0, 1].Properti ini berfungsi terbalik dibandingkan dengan bagian BasePart.Transparency atau PartikelEmitter's ParticleEmitter.Transparency : nilai 0 benar-benar tidak terlihat, 1 benar-benar terlihat.
Tekstur yang digunakan Roblox untuk partikel Smoke adalah sebagian transparan, jadi menetapkan properti ini ke 1 masih menghasilkan transparansi dalam asap yang drender
Contoh Kode
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 berperilaku serupa dengan ParticleEmitter.Speed dan Fire.Heat : ia menentukan seberapa cepat partikel asap bergerak selama masa hidupnya.Ini harus berada dalam rentang [-25, 25].Nilai negatif akan menyebabkan partikel dipancarkan ke arah bawah (-Y) dari orang tua BasePart .
Saat menggunakan efek Smoke untuk membuat kabut, atur properti ini menjadi 0.Untuk efek asap besar, buat peningkatan halus (2 hingga 8).Untuk perapian dan lubang asap, nilai yang lebih tinggi sesuai.
Contoh Kode
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
Properti Ukuran dari Smoke menentukan ukuran partikel asap yang baru dikeluarkan.Tidak seperti Smoke.Color , properti ini tidak akan mengubah ukuran partikel yang ada.Ini harus berada dalam rentang [0.1, 100].Tidak seperti ParticleEmitter.Size , properti ini hanya angka (bukan NumberSequence ).Perhatikan juga bahwa ukuran partikel tidak 1-ke-1 dengan stud; sebenarnya, ukuran partikel asap lebih dari dua kali lebih besar.Pada ukuran terbesar, partikel asap dapat menampilkan lebih besar dari 200 stud lebar!
Contoh Kode
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)
TimeScale
Nilai antara 0-1 lebih dari mengontrol kecepatan efek partikel.Pada 1 berjalan dengan kecepatan normal, pada 0.5 berjalan setengah kecepatan, dan pada 0 membekukan waktu.