Difference between revisions of "Particles:addParticles"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
'''Available since:''' Gideros 2016.06<br/>
 
'''Available since:''' Gideros 2016.06<br/>
 +
'''Class:''' [[Particles]]<br/>
 +
 
=== Description ===
 
=== Description ===
<translate>Add particle a single particle (short form) or several ones (long form) to this particle system.
+
Adds a single particle (short form) or several ones (long form) to a particle system.
<br/>
+
<syntaxhighlight lang="lua">
Short form (single particle):
+
(number or table) = Particles:addParticles(particles)
[[particles:addParticles(x,y,size,angle,ttl)]]
+
</syntaxhighlight>
<br/>
+
 
Extended form:
+
'''Short form''' (single particle): ''particles:addParticles(x,y,size,angle,ttl)''
[[particles:addParticles{particleDesc1,particleDesc2,...,particleDescN}]]
+
 
 +
'''Extended form''': ''particles:addParticles{particleDesc1,particleDesc2,...,particleDescN}''
 +
 
 
where particleDescX is a table describing a particle to be added. This table can contain the following parameters:
 
where particleDescX is a table describing a particle to be added. This table can contain the following parameters:
<ul>
+
*'''x''','''y''': particle position
<li>x,y: particle position</li>
+
*'''size''': particle size
<li>size: particle size</li>
+
*'''angle''': particle orientation
<li>angle: particle orientation</li>
+
*'''color''': particle color
<li>color: particle color</li>
+
*'''alpha''': particle alpha
<li>alpha: particle alpha</li>
+
*'''ttl''': time to live, number of frames this particle will stay on screen
<li>ttl: time to leave, number of frames this particle will stay on screen</li>
+
*'''tag''': tag associated with this particle
<li>tag: tag associated with this particle</li>
+
*'''speedX''', '''speedY''', '''speedAngular''', '''speedGrowth''': amount added to x, y, angle and size at the beginning of each frame
<li>speedX,speedY,speedAngular,speedGrowth: Amount added to x,y,angle and size at the beginning of each frame</li>
+
*'''decay''', '''decayAngular''', '''decayGrowth''', '''decayAlpha''': factor applied to speedX and speedY, speedAngular, speedGrowth and alpha at the beginning of each frame. A value below 1 will substract and a value above 1 will add to the current value.
<li>decay,decayAngular,decayGrowth,decayAlpha: factor applied to speedX and speedY, speedAngular, speedGrowth and alpha at the beginning of each frame</li>
+
*'''z''', '''speedZ''': z particle position and associated speed (since Gideros 2022.5)
</ul></translate>
+
*'''acceleration''', '''accelerationAngular''', '''accelerationGrowth''', '''accelerationAlpha''': amount added each frame to associated speed values (since Gideros 2022.5)
<source lang="lua">
+
*'''extra''': additional float value available in the shader (since Gideros 2022.5)
(number or table) = Particles:addParticles(particles)
+
 
</source>
+
 
 +
Since Gideros 2022.5, '''decay''' and '''acceleration''' can be vectors, allowing to specify different values for x,y and z components.
 +
 
 
=== Parameters ===
 
=== Parameters ===
'''particles''': (table or arguments) <translate>table for multiple particles or arguments for single</translate> <br/>
+
'''particles''': (table or arguments) table for multiple particles or arguments for single particle</br>
 +
 
 
=== Return values ===
 
=== Return values ===
'''Returns''' (number or table) <translate>index or table with indexes of added particles</translate><br/>
+
'''Returns''' (number or table) index or table with indexes of added particles</br>
 +
 
 +
=== Example ===
 +
<syntaxhighlight lang="lua">
 +
local stars = Particles.new()
 +
stars:setPosition(64, 64)
 +
stage:addChild(stars)
 +
stage:addEventListener(Event.ENTER_FRAME, function()
 +
stars:addParticles({
 +
{x=math.random(4*64),y=math.random(5*64),size=math.random(1,30),color=0xD9B589,ttl=1*60,speedX=0,speedY=0},
 +
{x=math.random(2*64),y=math.random(5*64),size=math.random(1,30),color=0xffff00,ttl=30*60,speedX=1,speedY=0},
 +
})
 +
end)
 +
</syntaxhighlight>
 +
 
 +
{{Particles}}

Latest revision as of 14:32, 13 July 2023

Available since: Gideros 2016.06
Class: Particles

Description

Adds a single particle (short form) or several ones (long form) to a particle system.

(number or table) = Particles:addParticles(particles)

Short form (single particle): particles:addParticles(x,y,size,angle,ttl)

Extended form: particles:addParticles{particleDesc1,particleDesc2,...,particleDescN}

where particleDescX is a table describing a particle to be added. This table can contain the following parameters:

  • x,y: particle position
  • size: particle size
  • angle: particle orientation
  • color: particle color
  • alpha: particle alpha
  • ttl: time to live, number of frames this particle will stay on screen
  • tag: tag associated with this particle
  • speedX, speedY, speedAngular, speedGrowth: amount added to x, y, angle and size at the beginning of each frame
  • decay, decayAngular, decayGrowth, decayAlpha: factor applied to speedX and speedY, speedAngular, speedGrowth and alpha at the beginning of each frame. A value below 1 will substract and a value above 1 will add to the current value.
  • z, speedZ: z particle position and associated speed (since Gideros 2022.5)
  • acceleration, accelerationAngular, accelerationGrowth, accelerationAlpha: amount added each frame to associated speed values (since Gideros 2022.5)
  • extra: additional float value available in the shader (since Gideros 2022.5)


Since Gideros 2022.5, decay and acceleration can be vectors, allowing to specify different values for x,y and z components.

Parameters

particles: (table or arguments) table for multiple particles or arguments for single particle

Return values

Returns (number or table) index or table with indexes of added particles

Example

local stars = Particles.new()
stars:setPosition(64, 64)
stage:addChild(stars)
stage:addEventListener(Event.ENTER_FRAME, function()
	stars:addParticles({
		{x=math.random(4*64),y=math.random(5*64),size=math.random(1,30),color=0xD9B589,ttl=1*60,speedX=0,speedY=0},
		{x=math.random(2*64),y=math.random(5*64),size=math.random(1,30),color=0xffff00,ttl=30*60,speedX=1,speedY=0},
	})
end)