Difference between revisions of "Particles"
(6 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> | '''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/> | ||
'''Available since:''' Gideros 2016.06<br/> | '''Available since:''' Gideros 2016.06<br/> | ||
− | '''Inherits from:''' [[ | + | '''Inherits from:''' [[Sprite]]<br/> |
=== Description === | === Description === | ||
A particle system which allows to draw several identical dots or bitmaps, with varying colour and orientation. | 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 === | === Example === | ||
− | < | + | '''Particles 2D''' |
+ | <syntaxhighlight lang="lua"> | ||
-- gideros particles | -- gideros particles | ||
local particleGFX = Texture.new("gfx/yourgfx.png") | local particleGFX = Texture.new("gfx/yourgfx.png") | ||
Line 41: | Line 44: | ||
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame) | stage:addEventListener(Event.ENTER_FRAME, onEnterFrame) | ||
− | </ | + | </syntaxhighlight> |
+ | |||
+ | '''Particles 3D''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | -- Set up a fullscreen 3D viewport | ||
+ | local sw,sh=application:getContentWidth(),application:getContentHeight() | ||
+ | local view=D3.View.new(sw,sh,45,0.1,1000) | ||
+ | stage:addChild(view) | ||
+ | local scene=view:getScene() | ||
+ | |||
+ | -- We will embed our particles in a 3D mesh, to enable depth testing | ||
+ | local sc=Mesh.new(true) | ||
+ | scene:addChild(sc) | ||
+ | -- A particle set showing a bubble, for a fountain | ||
+ | local fountain=Particles.new(true,true) | ||
+ | fountain:setTexture(Texture.new("Bubble.png",true)) | ||
+ | sc:addChild(fountain) | ||
+ | fountain:setX(0) | ||
+ | fountain:setY(0) | ||
+ | fountain:setZ(0) | ||
+ | |||
+ | -- Our emitter for fountain | ||
+ | function Particles:fountain() | ||
+ | local da=math.random()*6.28 | ||
+ | local dh=math.cos(os:clock()/2) | ||
+ | local dr=math.random()*.001+.008*math.sin(os:clock()/2) | ||
+ | self:addParticles({ | ||
+ | { | ||
+ | x=0,y=0,z=0, | ||
+ | size=.05,ttl=200, | ||
+ | speedY=.025+.025*math.abs(dh),speedX=dr*math.sin(da),speedZ=dr*math.cos(da), | ||
+ | decay=vector(1,1,1),acceleration=vector(0,-.0005,0), | ||
+ | color=math.random(0x0, 0xffffff), | ||
+ | } | ||
+ | }) | ||
+ | end | ||
+ | |||
+ | -- Look at it | ||
+ | view:lookAt(0,4,3, 0,0,0) | ||
+ | |||
+ | -- Game loop | ||
+ | stage:addEventListener(Event.ENTER_FRAME,function(e) | ||
+ | for i=1,16 do fountain:fountain() end | ||
+ | end) | ||
+ | </syntaxhighlight> | ||
{|- | {|- | ||
Line 51: | Line 98: | ||
[[Particles:clearTexture]] ''clears texture for all particles''<br/><!--GIDEROSMTD:Particles:clearTexture(slot) clears texture for all particles--> | [[Particles:clearTexture]] ''clears texture for all particles''<br/><!--GIDEROSMTD:Particles:clearTexture(slot) clears texture for all particles--> | ||
[[Particles:getDeadParticles]] ''gets dead particles''<br/><!--GIDEROSMTD:Particles:getDeadParticles() gets dead particles--> | [[Particles:getDeadParticles]] ''gets dead particles''<br/><!--GIDEROSMTD:Particles:getDeadParticles() gets dead particles--> | ||
− | [[Particles:getNearestParticle]] ''gets the index of the nearest particle to the given point''<br/><!--GIDEROSMTD:Particles:getNearestParticle(x,y) | + | [[Particles:getNearestParticle]] ''gets the index of the nearest particle to the given point''<br/><!--GIDEROSMTD:Particles:getNearestParticle(x,y) gets the index of the nearest particle to the given point--> |
+ | [[Particles:getNumParticles]] ''gets the number of active particles''<br/><!--GIDEROSMTD:Particles:getNumParticles() gets the number of active particles--> | ||
[[Particles:getParticleAcceleration]] ''gets particle acceleration''<br/><!--GIDEROSMTD:Particles:getParticleAcceleration(i) gets particle dacceleration--> | [[Particles:getParticleAcceleration]] ''gets particle acceleration''<br/><!--GIDEROSMTD:Particles:getParticleAcceleration(i) gets particle dacceleration--> | ||
[[Particles:getParticleAngle]] ''gets particle angle''<br/><!--GIDEROSMTD:Particles:getParticleAngle(i) gets particle angle--> | [[Particles:getParticleAngle]] ''gets particle angle''<br/><!--GIDEROSMTD:Particles:getParticleAngle(i) gets particle angle--> |
Latest revision as of 20:28, 21 September 2023
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
-- Set up a fullscreen 3D viewport
local sw,sh=application:getContentWidth(),application:getContentHeight()
local view=D3.View.new(sw,sh,45,0.1,1000)
stage:addChild(view)
local scene=view:getScene()
-- We will embed our particles in a 3D mesh, to enable depth testing
local sc=Mesh.new(true)
scene:addChild(sc)
-- A particle set showing a bubble, for a fountain
local fountain=Particles.new(true,true)
fountain:setTexture(Texture.new("Bubble.png",true))
sc:addChild(fountain)
fountain:setX(0)
fountain:setY(0)
fountain:setZ(0)
-- Our emitter for fountain
function Particles:fountain()
local da=math.random()*6.28
local dh=math.cos(os:clock()/2)
local dr=math.random()*.001+.008*math.sin(os:clock()/2)
self:addParticles({
{
x=0,y=0,z=0,
size=.05,ttl=200,
speedY=.025+.025*math.abs(dh),speedX=dr*math.sin(da),speedZ=dr*math.cos(da),
decay=vector(1,1,1),acceleration=vector(0,-.0005,0),
color=math.random(0x0, 0xffffff),
}
})
end
-- Look at it
view:lookAt(0,4,3, 0,0,0)
-- Game loop
stage:addEventListener(Event.ENTER_FRAME,function(e)
for i=1,16 do fountain:fountain() end
end)
MethodsParticles.new creates new particles group |
EventsConstants |