Difference between revisions of "Particles:addParticles"

From GiderosMobile
(removed language stuff)
m
Line 4: Line 4:
  
 
=== Description ===
 
=== Description ===
Add a single particle (short form) or several ones (long form) to a particle system.
+
Adds a single particle (short form) or several ones (long form) to a particle system.
 
<source lang="lua">
 
<source lang="lua">
 
(number or table) = Particles:addParticles(particles)
 
(number or table) = Particles:addParticles(particles)
Line 21: Line 21:
 
*ttl: time to live, number of frames this particle will stay on screen
 
*ttl: time to live, number of frames this particle will stay on screen
 
*tag: tag associated with this particle
 
*tag: tag associated with this particle
*speedX,speedY,speedAngular,speedGrowth: Amount added to x,y,angle and size at the beginning of each frame
+
*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
+
*decay, decayAngular, decayGrowth, decayAlpha: factor applied to speedX and speedY, speedAngular, speedGrowth and alpha at the beginning of each frame
  
 
=== Parameters ===
 
=== Parameters ===
'''particles''': (table or arguments) table for multiple particles or arguments for single
+
'''particles''': (table or arguments) table for multiple particles or arguments for single particle
  
 
=== Return values ===
 
=== Return values ===

Revision as of 18:47, 27 December 2021

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

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)