Difference between revisions of "Particles"

From GiderosMobile
(added example)
(→‎Example: the example wasn't working out of the box)
Line 11: Line 11:
 
<source lang="lua">
 
<source lang="lua">
 
-- gideros particles
 
-- gideros particles
local particleGFX = Texture.new("gfx/fx/smoke.png")
+
local particleGFX = Texture.new("gfx/yourgfx.png")
 
local stars = Particles.new()
 
local stars = Particles.new()
 
stars:setTexture(particleGFX)
 
stars:setTexture(particleGFX)
 
stage:addChild(stars)
 
stage:addChild(stars)
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
  
 
-- GAME LOOP
 
-- GAME LOOP
 
function onEnterFrame(e)
 
function onEnterFrame(e)
if (e.time // 1) % 2 == 0 then
+
if (e.time // 1) % 4 == 0 then
self.stars:addParticles({
+
stars:addParticles({
 
{
 
{
 
x=math.random(480),y=math.random(320),
 
x=math.random(480),y=math.random(320),
 
size=32,angle=math.random(360),
 
size=32,angle=math.random(360),
color=0xffffff,alpha=0.2,
+
color=0xff00ff,alpha=0.8,
ttl=16*64,
+
ttl=16*2,
 
speedX=0.01,speedY=0.01,speedAngular=0.15,
 
speedX=0.01,speedY=0.01,speedAngular=0.15,
speedGrowth=0.5,
+
speedGrowth=0.9,
 
},
 
},
 
{
 
{
 
x=math.random(480),y=math.random(320),
 
x=math.random(480),y=math.random(320),
size=24,angle=math.random(360/2),
+
size=16,angle=math.random(360),
color=0x0,alpha=0.2,
+
color=0x00ffff,alpha=0.8,
ttl=8*64,
+
ttl=16*16,
speedX=0.01,speedY=0.01,speedAngular=0.015,
+
speedX=0.02,speedY=0.02,speedAngular=0.2,
speedGrowth=0.5,
+
speedGrowth=-0.1,
 
},
 
},
 
})
 
})
 
end
 
end
 
end
 
end
 +
 +
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
</source>
 
</source>
  
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 +
 
=== Methods ===
 
=== Methods ===
 
[[Particles.new]] ''creates new particles group''<br/><!--GIDEROSMTD:Particles.new() creates a new particles group-->
 
[[Particles.new]] ''creates new particles group''<br/><!--GIDEROSMTD:Particles.new() creates a new particles group-->

Revision as of 01:09, 12 January 2022

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2016.06
Inherits from: Sprite

Description

A particle system which allows to draw several identical dots or bitmaps, with varying colour and orientation.

Example

-- gideros particles
local particleGFX = Texture.new("gfx/yourgfx.png")
local stars = Particles.new()
stars:setTexture(particleGFX)
stage:addChild(stars)

-- GAME LOOP
function onEnterFrame(e)
	if (e.time // 1) % 4 == 0 then
		stars:addParticles({
			{
				x=math.random(480),y=math.random(320),
				size=32,angle=math.random(360),
				color=0xff00ff,alpha=0.8,
				ttl=16*2,
				speedX=0.01,speedY=0.01,speedAngular=0.15,
				speedGrowth=0.9,
			},
			{
				x=math.random(480),y=math.random(320),
				size=16,angle=math.random(360),
				color=0x00ffff,alpha=0.8,
				ttl=16*16,
				speedX=0.02,speedY=0.02,speedAngular=0.2,
				speedGrowth=-0.1,
			},
		})
	end
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

Methods

Particles.new creates new particles group
Particles:addParticles adds particles
Particles:clearTexture clears texture for all particles
Particles:getNearestParticle gets the index of the nearest particle to the given point
Particles:getParticleAngle gets particle angle
Particles:getParticleColor gets particle color and alpha value
Particles:getParticleDecay gets particle decay factor
Particles:getParticlePosition gets particle position
Particles:getParticleSize gets particle size in pixels
Particles:getParticleSpeed gets particle speed
Particles:getParticleTag gets particle associated tag
Particles:getParticleTtl gets particle initial time to live
Particles:getParticles gets particles
Particles:isPaused tells if the Particle set is paused
Particles:removeParticles removes particles by index in table or as arguments
Particles:scaleParticles scales or resizes all particles in this sprite
Particles:setParticleAngle sets particle angle
Particles:setParticleColor sets particle color
Particles:setParticleDecay sets particle decay factor
Particles:setParticlePosition sets particle position
Particles:setParticleSize sets particle size
Particles:setParticleSpeed sets particle speed
Particles:setParticleTag sets particle tag
Particles:setParticleTtl sets particle time to live
Particles:setPaused pauses or resumes the Particle set
Particles:setTexture sets texture to all particles

Events

Constants