Particles
Supported platforms: ![]()
![]()
![]()
![]()
![]()
![]()
![]()
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.
Note: starting from Gideros 2022.5, Particles 3D was added
Example
Particles 2D
-- 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)
Particles 3D
application:setBackgroundColor(0x5500ff)
local abs, cos, sin, random = math.abs, math.cos, math.sin, math.random
-- set up the 3D view and projection
local sw, sh = application:getContentWidth(), application:getContentHeight()
local projection = Matrix.new()
projection:perspectiveProjection(60, sw/sh, 0.01, 1000) -- fov, aspect, near, far
local view = Viewport.new()
view:setProjection(projection)
view:setPosition(sw/2, sh/2)
view:setScale(sw, -sh, 1)
-- a particle set showing a bubble, for a fountain
local fountain = Particles.new(true, true)
--fountain:setTexture(Texture.new("bubble.png"))
-- position
fountain:setX(0)
fountain:setY(0)
fountain:setZ(0)
-- order
view:setContent(fountain)
stage:addChild(view)
-- look at it
view:lookAt(0,-4,-2, fountain:getX(),fountain:getY(),fountain:getZ(), 0,1,0)
-- our emitter for fountain
function Particles:fountain()
local da = random()*6.28
local dh = cos(os:clock()/2)
local dr = random()*.001+.008*sin(os:clock()/2)
self:addParticles({
{
x=0, y=0, z=0,
size=.04, ttl=196,
speedY=.02+.02*abs(dh), speedX=dr*sin(da), speedZ=dr*cos(da),
decay=vector(1,1,1), acceleration=vector(0,-.0005,0),
color=random(0xff00ff),
}
})
end
-- game loop
stage:addEventListener(Event.ENTER_FRAME,function(e)
for i = 1, 8 do fountain:fountain() end
end)
MethodsParticles.new creates new particles group |
EventsConstants |