Type Function Library physics.* Return value ParticleSystem Revision Release 2022.3683 Keywords newParticleSystem, physics, particle, LiquidFun See also object:createParticle() object:createGroup()
A ParticleSystem object contains particles with liquid-like behavior under the LiquidFun framework.
Once you create a particle system, you can generate particles using object:createParticle() or object:createGroup().
Particles can only collide with other particles in the same particle system.
To remove a particle system, use particleSystem:removeSelf()
or display.remove( particleSystem )
.
This call cannot be used in a collision event. However, your collision handler may set a flag or include a time delay via timer.performWithDelay() so that the action can occur in the next application cycle or later. See the Collision Detection guide for a complete list of which APIs and methods are subject to this rule.
physics.newParticleSystem( params )
Table. A table that specifies the properties of the particle system — see the next section for valid entries.
String. The name of the texture file you want to use for each individual particle instance.
Constant. By default, texture files are expected to be in the project folder (system.ResourceDirectory
). If the texture file is in the documents directory, use system.DocumentsDirectory
.
Number. This numerical property controls the density of particles. This value is 1.0
by default.
Number. This numerical property controls the scaling of gravity. This value is 1.0
by default.
Number. The radius of the physical body for each generated particle.
Number. If defined, the particle image will be rendered at a different radius than the physical body. Otherwise, the image will be rendered at the value of radius
.
Number. This numerical property controls the maximum number of particles. This value is 0
by default, indicating no maximum limit.
Number. Increases pressure in response to compression. Smaller values allow more compression.
Number. Reduces velocity along the collision normal. Smaller value reduces less.
Number. Restores shape of elastic particle groups. Larger values increase elastic particle velocity.
Number. Restores length of spring particle groups. Larger values increase sprint particle velocity.
Number. Reduces relative velocity of viscous particles. Larger values slow down viscous particles more.
Number. Produces pressure on tensile particles in a range of about 0
to 0.2
. Larger values increase the amount of surface tension.
Number. Smoothes outline of tensile particles in a range of about 0
to 0.2
. Larger values result in rounder, smoother,
Number. Produces additional pressure on repulsive particles. Larger values repulse more and negative values mean attraction. The stability range of particles is about -0.2
to 2.0
.
Number. Produces repulsion between powder particles. Larger values repulse more.
Number. Pushes particles out of solid particle group. Larger values repulse more.
Number. Produces static pressure. Larger values increase the pressure on neighboring particles. For a description of static pressure, refer here.
Number. Reduces instability in static pressure calculation. Larger values stabilize static pressure with fewer iterations.
Number. Changes the number of iterations when calculating the static pressure of particles. By default this is 8
iterations. You can reduce the number of iterations down to 1
in some situations, but this may cause instability when many particles come together. If you see particles popping away from each other like popcorn, you may have to increase the number of iterations. For a description of static pressure, refer here.
Boolean. Specifies whether the strict particle/body contact check should be enabled. This value is false
by default.
Number. Determines how fast colors are mixed. A value of 1.0
mixes particles immediately while a value of 0.5
mixes particles halfway on each simulation step.
Boolean. Specifies whether to destroy particles by age when no more particles can be created.
Number. Granularity of particle lifetimes in seconds. The maximum lifetime of a particle is (2^32 - 1) / (1.0f / lifetimeGranularity)
seconds, so with the value set to 1/60
the maximum lifetime or age of a particle is 2.27 years.
String. Sets the particle blending equation. Acceptable values are "subtract"
, "reverseSubtract"
, or "disabled"
.
String or Table. Sets the particle blending mode. Acceptable string values are "add"
, "multiply"
, "screen"
, or "normal"
. This can also be a table of
blendMode = { srcColor="one", srcAlpha="one", dstColor="one", dstAlpha="one" }
local particleSystem = physics.newParticleSystem( { filename = "particle.png", radius = 3 } )
local particleSystem = physics.newParticleSystem( { filename = "particle.png", radius = 4, imageRadius = 6, colorMixingStrength = 0.1, blendMode = "add" } )