Lớp công cụ
ParticleEmitter
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Texture:ContentId |
Mẫu mã
Tạo một Bộ phát Hạt từ đầu
local emitter = Instance.new("ParticleEmitter")
-- Số lượng hạt = Tỷ lệ * Thời gian sống
emitter.Rate = 5 -- Hạt mỗi giây
emitter.Lifetime = NumberRange.new(1, 1) -- Thời gian sống của hạt (tối thiểu, tối đa)
emitter.Enabled = true
-- Thuộc tính hình ảnh
emitter.Texture = "rbxassetid://1266170131" -- Một hình ảnh trong suốt của vòng tròn màu trắng
-- Đối với Màu, tạo một ColorSequence bằng ColorSequenceKeypoint
local colorKeypoints = {
-- API: ColorSequenceKeypoint.new(thời gian, màu sắc)
ColorSequenceKeypoint.new(0, Color3.new(1, 1, 1)), -- Tại t=0, Màu trắng
ColorSequenceKeypoint.new(0.5, Color3.new(1, 0.5, 0)), -- Tại t=.5, Màu cam
ColorSequenceKeypoint.new(1, Color3.new(1, 0, 0)), -- Tại t=1, Màu đỏ
}
emitter.Color = ColorSequence.new(colorKeypoints)
local numberKeypoints = {
-- API: NumberSequenceKeypoint.new(thời gian, kích thước, bao bọc)
NumberSequenceKeypoint.new(0, 1), -- Tại t=0, hoàn toàn trong suốt
NumberSequenceKeypoint.new(0.1, 0), -- Tại t=.1, hoàn toàn không trong suốt
NumberSequenceKeypoint.new(0.5, 0.25), -- Tại t=.5, chủ yếu không trong suốt
NumberSequenceKeypoint.new(1, 1), -- Tại t=1, hoàn toàn trong suốt
}
emitter.Transparency = NumberSequence.new(numberKeypoints)
emitter.LightEmission = 1 -- Khi các hạt chồng lên nhau, nhân màu của chúng để sáng hơn
emitter.LightInfluence = 0 -- Không bị ảnh hưởng bởi ánh sáng thế giới
-- Thuộc tính tốc độ
emitter.EmissionDirection = Enum.NormalId.Front -- Phát ra về phía trước
emitter.Speed = NumberRange.new(0, 0) -- Tốc độ bằng không
emitter.Drag = 0 -- Không áp dụng lực kéo vào chuyển động của hạt
emitter.VelocitySpread = NumberRange.new(0, 0)
emitter.VelocityInheritance = 0 -- Không thừa hưởng tốc độ của cha
emitter.Acceleration = Vector3.new(0, 0, 0)
emitter.LockedToPart = false -- Không khóa các hạt vào cha
emitter.SpreadAngle = Vector2.new(0, 0) -- Không có góc tỏa rộng trên bất kỳ trục nào
-- Thuộc tính mô phỏng
local numberKeypoints2 = {
NumberSequenceKeypoint.new(0, 0), -- Tại t=0, kích thước là 0
NumberSequenceKeypoint.new(1, 10), -- Tại t=1, kích thước là 10
}
emitter.Size = NumberSequence.new(numberKeypoints2)
emitter.ZOffset = -1 -- Hiển thị hơi phía sau vị trí thực tế
emitter.Rotation = NumberRange.new(0, 360) -- Bắt đầu ở góc ngẫu nhiên
emitter.RotSpeed = NumberRange.new(0) -- Không xoay trong quá trình mô phỏng
-- Tạo một điểm gắn để các hạt phát ra từ cùng một vị trí chính xác (các vòng tròn đồng tâm)
local attachment = Instance.new("Attachment")
attachment.Position = Vector3.new(0, 5, 0) -- Di chuyển điểm gắn lên một chút
attachment.Parent = script.Parent
emitter.Parent = attachmentTài Liệu Tham Khảo API
Thuộc Tính
Texture
ParticleEmitter.Texture:ContentId
VelocitySpread
Phương Pháp
Clear
ParticleEmitter:Clear():()
Lợi Nhuận
()
Mẫu mã
Phát Tán Hạt Nổ
local emitter = script.Parent
while true do
emitter:Clear()
emitter:Emit(10)
task.wait(2)
endEmit
Tham Số
| Giá Trị Mặc Định: 16 |
Lợi Nhuận
()
Mẫu mã
Phát Hạt Trong Khoảng Cách
local RunService = game:GetService("RunService")
local emitter = script.Parent
local part = emitter.Parent
local PARTICLES_PER_STUD = 3
local lastPosition = part.Position
local distance = 0
local function onStep()
local displacement = part.Position - lastPosition
distance = distance + displacement.magnitude
local n = math.floor(distance * PARTICLES_PER_STUD)
emitter:Emit(n)
distance = distance - n / PARTICLES_PER_STUD
lastPosition = part.Position
end
RunService.Stepped:Connect(onStep)
emitter.Enabled = falsePhát Tán Hạt Nổ
local emitter = script.Parent
while true do
emitter:Clear()
emitter:Emit(10)
task.wait(2)
end