ParticleEmitter

显示已弃用

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

ParticleEmitter 是一个特殊对象,它可以将可定制的 2D 粒子发射到世界。要发射和渲染粒子,它必须被父级到一个 Class.BasePart 或一个 Class.附件

当发射器处于 Enabled 且没有零Rate 时,或手动设置Emit 方法时,粒子会自

默认情况下,粒子面向相镜头,但 Orientation 可以修改为尊重粒子速度。

在粒子的 Lifetime 期间,

了解有关创建和自定义粒子发射器的更多信息,请参阅粒子发射器

代码示例

This rather lengthy code sample shows how every property of a ParticleEmitter can be set, including NumberRange, NumberSequence and ColorSequence properties. Below is how the ParticleEmitter should look after every property is set. Try playing around with the different properties to customize how the effect looks!

Creating a Particle Emitter from Scratch

local emitter = Instance.new("ParticleEmitter")
-- Number of particles = Rate * Lifetime
emitter.Rate = 5 -- Particles per second
emitter.Lifetime = NumberRange.new(1, 1) -- How long the particles should be alive (min, max)
emitter.Enabled = true
-- Visual properties
emitter.Texture = "rbxassetid://1266170131" -- A transparent image of a white ring
-- For Color, build a ColorSequence using ColorSequenceKeypoint
local colorKeypoints = {
-- API: ColorSequenceKeypoint.new(time, color)
ColorSequenceKeypoint.new(0, Color3.new(1, 1, 1)), -- At t=0, White
ColorSequenceKeypoint.new(0.5, Color3.new(1, 0.5, 0)), -- At t=.5, Orange
ColorSequenceKeypoint.new(1, Color3.new(1, 0, 0)), -- At t=1, Red
}
emitter.Color = ColorSequence.new(colorKeypoints)
local numberKeypoints = {
-- API: NumberSequenceKeypoint.new(time, size, envelop)
NumberSequenceKeypoint.new(0, 1), -- At t=0, fully transparent
NumberSequenceKeypoint.new(0.1, 0), -- At t=.1, fully opaque
NumberSequenceKeypoint.new(0.5, 0.25), -- At t=.5, mostly opaque
NumberSequenceKeypoint.new(1, 1), -- At t=1, fully transparent
}
emitter.Transparency = NumberSequence.new(numberKeypoints)
emitter.LightEmission = 1 -- When particles overlap, multiply their color to be brighter
emitter.LightInfluence = 0 -- Don't be affected by world lighting
-- Speed properties
emitter.EmissionDirection = Enum.NormalId.Front -- Emit forwards
emitter.Speed = NumberRange.new(0, 0) -- Speed of zero
emitter.Drag = 0 -- Apply no drag to particle motion
emitter.VelocitySpread = NumberRange.new(0, 0)
emitter.VelocityInheritance = 0 -- Don't inherit parent velocity
emitter.Acceleration = Vector3.new(0, 0, 0)
emitter.LockedToPart = false -- Don't lock the particles to the parent
emitter.SpreadAngle = Vector2.new(0, 0) -- No spread angle on either axis
-- Simulation properties
local numberKeypoints2 = {
NumberSequenceKeypoint.new(0, 0), -- At t=0, size of 0
NumberSequenceKeypoint.new(1, 10), -- At t=1, size of 10
}
emitter.Size = NumberSequence.new(numberKeypoints2)
emitter.ZOffset = -1 -- Render slightly behind the actual position
emitter.Rotation = NumberRange.new(0, 360) -- Start at random rotation
emitter.RotSpeed = NumberRange.new(0) -- Do not rotate during simulation
-- Create an attachment so particles emit from the exact same spot (concentric rings)
local attachment = Instance.new("Attachment")
attachment.Position = Vector3.new(0, 5, 0) -- Move the attachment upwards a little
attachment.Parent = script.Parent
emitter.Parent = attachment

概要

属性

方法

  • Clear():void

    清除所有发射的粒子。

  • Emit(particleCount : number):void

    发出给定的粒子数。

属性

Acceleration

读取并联

加速器属性确定加速器的速度在其生命时间变化。它使用 Datatype.Vector3 来确定加速器在全球 Speed / Vector3 / 2>Z2> 轴上的加速。当改变时,这个属性会影响 emitter 的所有发

加速会使溢出的粒子速度降低,如果它们发射在 EmissionDirection 中,它们的溢出速度会变慢。否则,它会加速它们。

Brightness

读取并联

ParticleEmitter.LightInfluence 为 0 时,调整发射器发出的光。

读取并联

颜色 属性确定了所有有效的粒子在其个〖个生命时间〖的颜色。颜色适用于Class.ParticleEmitter.Texture|Texture,当它在渲染时使用粒子的Texture。如果Class.ParticleEmitter

改变此属性会影响 emitter 的所有发射器,当前和未来。

当这个属性使用一个渐变 ColorSequence 时,粒子的现有颜色是由线性使用粒子的年龄和总生命时间来确定的。例如,如果粒子 2 秒前生成,并且有 4 秒的生命时间,颜色将是由 50% 通过 Datatype.ColorSequ 的总生命值决定的。

Drag

读取并联

拖动属性确定个体粒子在使用叠加式衰减时以何种速度失去半速。拖动通过缩放预期速度从 Class.ParticleEmitter.Speed|Speed 和任何速度由父级从 Speed 继承的速度。设置此属性为负值会使粒子的

EmissionDirection

读取并联

EmissionDirection 属性确定父对象的脸( Class.ParticleEmitter.Speed|Speed )。一个负向 Class.ParticleEmitter.SpreadAngle|SpreadAngle 代表粒子在相反方向发射。1> Class.ParticleEmitter.SpreadAngle|SpreadAngle 更改了发射方向。1>

如果您将 ParticleEmitter 添加到 Attachment (具有方向),而使用此属性,您可以在上下文中使用附件自身(Attachment.Orientation)而不是使用此属性。

Enabled

读取并联

启用 属性决定是否从发射器发出粒子。将其设置为 false 会使粒子不再生成,但任何已生成的粒子都会保持有效,直到它们过期。此属性有助于您设置一个预制粒子效果,您想要使其无效直到您需要它才能生成粒子。

如果要从禁用发射器中清除所有粒子,请调用 Clear() 。然后,如果需要,请在发射器上调用 Emit() 来发射和渲染粒子。

FlipbookFramerate

读取并联

FlipbookFramerate 属性决定每秒钟秒内翻页的图像动画速度。喜欢 Lifetime ,您可以设置一个最低和最大范围来随机化翻页的图像动画,最多 30 个框架每秒钟。

FlipbookIncompatible

读取并联

如果 Texture 在翻译书上不兼容,显示错误消息。翻译书的材质必须为 8×8、16×16、32×32、64×64、128×128、256×256、512×512、或 1024×1024 。

读取并联

FlipbookLayout 属性决定着花纸的布局。它可以是 Enum.ParticleFlipbookLayout 枚的任意值:

  • – 禁用翻译功能,并将纹理用作单个静电纹理在粒子的整个生命时间。
  • 网格2x2 – 4个框架动画的 2 × 2 框架。
  • Grid4x4 – 16 个框架的 4 × 4 网格动画。
  • Grid8x8 – 64 个框架的 8×8 动画架。
读取并联

FlipbookMode 属性确定翻页动画的类型。它可以是 Enum.ParticleFlipbookMode 枚列表的任何值:

  • 循环播放 – 持续播放通过所有框架,从最后一个框架开始。
  • 一击射击 – 通过动画在粒子的整个生命时间只播放一次。 使用此设置, FlipbookFramerate 属性不适用;
  • PingPong – 从第一个到最后一个框架,然后从最后一个到第一个,重复在 Lifetime 的粒子。
  • 随机 – 在随机顺序中播放框架,从一个框架到另一个框架之间进行混合/渐变。这可能有助于低速框架上的有机粒子材质,例如星在不同形状之间慢慢闪烁。

FlipbookStartRandom

读取并联

FlipbookStartRandom 属性决定每个粒子在动画的随机框架开始,而不是总是从第一个框架开始。一个使用案例是启用此属性并将 FlipbookFramerate 设置为零,导致每个发射的粒子都是随机从翻书纹理中选择的静态框架。

Lifetime

读取并联

使用期 属性定义了新发射的粒子的最大和最小年龄。使用期存储在每个粒子上,因此如果此值改变,现有粒子将保持有效直到它们随机选择的使用期结束。0 将粒子的发射量防止在 0 。

LightEmission

读取并联

发光表面积计算器 属性确定了 Texture 与颜色之间的混合。一个值为 0 使用 普通 混合模式,而一个值为 1 使用 添加 混合模式。当改变时,这个属性立即影响所有拥有发光表面积的粒子,包括当前和未来的所有粒子。

这个属性不应与 LightInfluence ,它是确定粒子受到环境光的影响的方法。

这个属性会导致粒子在其周围的环境亮起。要实现此目标,请考虑使用一个 Class.PointLight 。

LightInfluence

读取并联

LightInfluence 属性决定环境光对单个粒子的颜色在渲染时受到多少影响。它必须在 0-1 之间; 在此范围之外的行为对值不起作用 。 在 0 下,粒子不受到光的影响 (它们保留全部亮度); 在 1 下,粒子受到完全的光影响 (在完全黑暗中,粒子会保持完全的亮度)。

默认情况下,这个值是 1 如果使用 Studio 工具插入。 如果使用 Instance.new() 插入,它是 0。

LocalTransparencyModifier

隐藏
未复制
读取并联

LockedToPart

读取并联

锁定到部分 属性决定是否允许粒子“贴”到发射源(AttachmentBasePart ),其父对象是 1> Class.ParticleEmitter1> 。如果4> true4>,活跃粒子将在锁定步骤移动,如果父对象移动,它

或者,考虑使用 VelocityInheritance 属性,其值为 1,这可能对某些效果更适合。

读取并联

定向属性确定发射器的粒子几何图形的使用哪种方向模式。


<tbody>
<tr>
<td><b>面向相机</b></td>
<td>标准的反向广告牌四面; 默认行为。</td>
</tr>
<tr>
<td><b>面向世界上的相机世界</b></td>
<td>面向相镜头,但仅在垂直向上世界 <b>Y</b> 轴上旋转。</td>
</tr>
<tr>
<td><b>速率平行</b></td>
<td>与其移动方向对齐。</td>
</tr>
<tr>
<td><b>垂直速度</b></td>
<td>与其方向移动对齐。</td>
</tr>
</tbody>
导航粒子行为

Rate

读取并联

Rate 属性确定发射器每秒钟发射的粒子数,发射器 Enabled 。它是频率的反向,因此频率越高,发射器每 0.2 秒就会发射一颗粒子。当发生变更时,该属性对任何已激活的粒子都无影响。

RotSpeed

读取并联

RotSpeed 属性确定了一个随机的角度速度对于新发射的粒子,它们以每秒度数量计量。随机角度速度在发射时被选择,因此修改此属性不会影响激活粒子。此属性与 Rotation ,影响射线的渲染图像角度。

角度很高的粒子可能会旋转更慢或不旋转 at al全部,因为旋转角度与软件渲染速度同步。例如,如果粒子在每个帧上旋转 360 度,那么旋转角度不会有任何显著的更改。

Rotation

读取并联

旋转 属性确定新发射的粒子的旋转度数,用于用户界面的显示。 正向值在时钟方向。 此属性通常设置为 [0, 360] 来为新发射的粒子提供一个完全随机的旋转。 RotSpeed 也会影响粒子在其生命时间的

改变此值只会影响新的粒子;现有的粒子会保持其原始旋转。

读取并联

Shape 属性设置发射器的形状为“方块子”、“球”、“圆柱”或“盘子”。 在您选择后,您可以调整ShapeStyleShapeInOut

读取并联

设置粒子是否仅向外发射,仅向内发射或向两个方向发射。对于视觉示例,请参阅这里

ShapePartial

读取并联

根据 Shape 值,此属性执行不同的动作:

  • 对于圆柱,它的上限轮廓是圆柱的顶部。一个值为 0 表示顶部的圆柱没有任何半径,因此它是一个锥体。一个值为 1 表示圆柱没有任何变形。

  • 对于圆盘,它指定内部圆度比例。一个值为 0 表示圆盘完全关闭 (圆/椭圆),而一个值为 1 表示仅在圆盘外部边缘发生发射。在 0 和 1 之间的值发生从一个特定的深度的 annulus 。

  • 对于球体,它指定球体上发射的方向角。一个值为 1 表示球体上发射的所有部分;一个值为 0.5 表示球体上发射的半球;一个值为 0 表示只发射一个点在北极上。

了解有关视觉示例,请参阅这里

读取并联

将粒子排放设置为“音量”或“表面”。对于视觉示例,请参阅这里

读取并联

大小属性确定世界上所有的有效粒子的个人生命时间上的世界尺寸。该属性代表每个粒子的方块 Texture 的尺寸。它是一个 NumberSequence ,它的工作方式与 1> Class.ParticleEmitter.Transparency|Transparency1> 相似。

粒子的现有大小由使用粒子的年龄和总生命时间来线性处理此序列中的每个字符确定。例如,如果粒子 2 秒前生成,并且具有 4 秒的总生命时间,粒子的大小将是确定的。 为了任何 Datatype.NumberSequ

读取并联

速度属性确定一个随机范围的速度(最低到最大)在新的粒子发出,用每秒计量的速度(每秒)。每个粒子的速度都是在发射时选择的,并且在Class.ParticleEmitter.EmissionDirection|EmissionDirection中应用。负值会导致粒子在向后旅行。

注意,改变 Speed 不会影响已激活的粒子,它们保留他们已有的速度。但是, AccelerationDrag 和 1> Class.ParticleEmitter.Vel

SpreadAngle

读取并联

撒射角度 属性确定随机角度,在哪个角度下发射粒子。例如,如果 EmissionDirection (+ 1>Y1>), 此 4>Datatype.Vector24> 描述在 <

将一个轴设置为 360 会导致粒子在 内的所有方向发射。将两个设置为 360 会导致粒子在 内的所有方向发射。

读取并联

允许非标准的粒子缩放,曲线控制在其生命时间上。大于 0 的值会导致粒子收缩横向,而小于 0 的值会导致粒子垂直向上生长。值小于 0 的值会导致粒子垂直向下生长。

Texture

ContentId
读取并联

纹理 属性决定在粒子上渲染的图像。 此图像受到 ColorTransparency 、1> Class.ParticleEmitter.LightInfluence|LightInfluence1> 和

TimeScale

读取并联

一个值在 0 和 1 之间,可以控制粒子效果的速度。 在 1 时,它以正常速度运行; 在 0.5 时,它以半速运行; 在 0 时,它冻结在时间。

Transparency

读取并联

透明度 属性决定了所有激活的粒子在其个人生命时间上的透明度。它与 Size 在如何影响粒子过时方面的工作方式相似。在渲染方面,一个值为 0 是完全可见的 (opaque),一个值为 1 是完全隐藏的 (不会在全部何情况下渲染)。

粒子的现实透明度是由使用粒子的年龄和总生命时间来线性处理的。例如,如果粒子 2 秒前生成,并且具有 4 秒的生命时间,粒子的透明度将是它在 Datatype.NumberSequ

VelocityInheritance

读取并联

VelocityInheritance 属性确定子弹部件的 Velocity 是否被子弹发射时的粒子继承。值为 0 表示无需继承速度,而值为 1 表示粒子将以父子 BasePart 的相同速度传播。

使用 Drag 与 Class.ParticleEmitter.Drag|Drag 结合时,粒子发射器可能会出现“落下”粒子从移动部件上移动的情况。

WindAffectsDrag

读取并联

如果是,发射的粒子跟随 Workspace.GlobalWind 矢量力。仅适用于 Drag 属性大于 0 时。

ZOffset

读取并联

ZOffset 属性确定粒子在屏幕上的前后视图位置,不会改变其大小。当改变时,这个属性会影响当前和未来的粒子。注意,这个属性接受浮点值;它不是 GuiObject.ZIndex (一个整数) 的。

正向值将粒子移动到相机附近,负向值将粒子移动到远处。足够负的值可以使粒子在父亲部分内或在后方渲染。

方法

Clear

void

清除方法立即清除 Class.ParticleEmitter 通过其自然排放 (不是零 ParticleEmitter 在一个 Rate 上的排放) 或通过 2>Class.ParticleEmitter:emit()2> 发出的所有现有粒子 (5>Class.ParticleEmitter:</


返回

void

代码示例

This code sample causes a ParticleEmitter to ParticleEmitter:Emit() particles in bursts of 10 every 2 seconds. It ParticleEmitter:Clear()s any existing particles before doing so.

ParticleEmitter Burst

local emitter = script.Parent
while true do
emitter:Clear()
emitter:Emit(10)
task.wait(2)
end

Emit

void

发射方法会使 Class.ParticleEmitter 立即发射指定的粒子数。

参数

particleCount: number

要发射的粒子数量。

默认值:16

返回

void

代码示例

This code sample causes a parent ParticleEmitter to ParticleEmitter:Emit() particles based on how far the parent BasePart moves.

Emit Particles Over Distance

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 = false

This code sample causes a ParticleEmitter to ParticleEmitter:Emit() particles in bursts of 10 every 2 seconds. It ParticleEmitter:Clear()s any existing particles before doing so.

ParticleEmitter Burst

local emitter = script.Parent
while true do
emitter:Clear()
emitter:Emit(10)
task.wait(2)
end

活动