Difference between revisions of "love.graphics.newParticleSystem"

(Add example.)
m
 
(4 intermediate revisions by 3 users not shown)
Line 8: Line 8:
 
=== Arguments ===
 
=== Arguments ===
 
{{param|Image|image|The image to use.}}
 
{{param|Image|image|The image to use.}}
{{param|number|buffer|The max number of particles at the same time.}}
+
{{param|number|buffer (1000)|The max number of particles at the same time.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|ParticleSystem|system|A new ParticleSystem.}}
 
{{param|ParticleSystem|system|A new ParticleSystem.}}
Line 19: Line 19:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|Texture|texture|The texture (Image or Canvas) to use.}}
+
{{param|Texture|texture|The texture ([[Image]] or [[Canvas]]) to use.}}
{{param|number|buffer|The max number of particles at the same time.}}
+
{{param|number|buffer (1000)|The max number of particles at the same time.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|ParticleSystem|system|A new ParticleSystem.}}
 
{{param|ParticleSystem|system|A new ParticleSystem.}}
Line 26: Line 26:
 
== Examples ==
 
== Examples ==
 
=== Creation and usage of a particle system ===
 
=== Creation and usage of a particle system ===
You can use the [https://www.love2d.org/w/images/9/9b/Love-game-logo-256x256.png löve logo] as an example image.
+
You can use the [[:File:Love-game-logo-256x256.png|LÖVE logo]] as an example image.
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()
local img = love.graphics.newImage('logo.png');
+
local img = love.graphics.newImage('logo.png')
  
psystem = love.graphics.newParticleSystem(img, 32);
+
psystem = love.graphics.newParticleSystem(img, 32)
psystem:setParticleLifetime(2, 5); -- Particles live at least 2s and at most 5s.
+
psystem:setParticleLifetime(2, 5) -- Particles live at least 2s and at most 5s.
psystem:setEmissionRate(5);
+
psystem:setEmissionRate(5)
psystem:setSizeVariation(1);
+
psystem:setSizeVariation(1)
psystem:setLinearAcceleration(-20, -20, 20, 20); -- Random movement in all directions.
+
psystem:setLinearAcceleration(-20, -20, 20, 20) -- Random movement in all directions.
psystem:setColors(255, 255, 255, 255, 255, 255, 255, 0); -- Fade to black.
+
psystem:setColors(1, 1, 1, 1, 1, 1, 1, 0) -- Fade to transparency.
 
end
 
end
  
 
function love.draw()
 
function love.draw()
 
-- Draw the particle system at the center of the game window.
 
-- Draw the particle system at the center of the game window.
love.graphics.draw(psystem, love.graphics.getWidth() * 0.5, love.graphics.getHeight() * 0.5);
+
love.graphics.draw(psystem, love.graphics.getWidth() * 0.5, love.graphics.getHeight() * 0.5)
 
end
 
end
  
 
function love.update(dt)
 
function love.update(dt)
psystem:update(dt);
+
psystem:update(dt)
 
end
 
end
 
</source>
 
</source>
Line 51: Line 51:
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]
 +
* [[ParticleSystem:clone]]
 
* [[Constructs::ParticleSystem]]
 
* [[Constructs::ParticleSystem]]
 
[[Category:Functions]]
 
[[Category:Functions]]

Latest revision as of 23:26, 7 March 2019

Creates a new ParticleSystem.

O.png This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!  



Function

Synopsis

system = love.graphics.newParticleSystem( image, buffer )

Arguments

Image image
The image to use.
number buffer (1000)
The max number of particles at the same time.

Returns

ParticleSystem system
A new ParticleSystem.

Function

Available since LÖVE 0.9.1
This variant is not supported in earlier versions.

Synopsis

system = love.graphics.newParticleSystem( texture, buffer )

Arguments

Texture texture
The texture (Image or Canvas) to use.
number buffer (1000)
The max number of particles at the same time.

Returns

ParticleSystem system
A new ParticleSystem.

Examples

Creation and usage of a particle system

You can use the LÖVE logo as an example image.

function love.load()
	local img = love.graphics.newImage('logo.png')

	psystem = love.graphics.newParticleSystem(img, 32)
	psystem:setParticleLifetime(2, 5) -- Particles live at least 2s and at most 5s.
	psystem:setEmissionRate(5)
	psystem:setSizeVariation(1)
	psystem:setLinearAcceleration(-20, -20, 20, 20) -- Random movement in all directions.
	psystem:setColors(1, 1, 1, 1, 1, 1, 1, 0) -- Fade to transparency.
end

function love.draw()
	-- Draw the particle system at the center of the game window.
	love.graphics.draw(psystem, love.graphics.getWidth() * 0.5, love.graphics.getHeight() * 0.5)
end

function love.update(dt)
	psystem:update(dt)
end

See Also


Other Languages