Difference between revisions of "ParticleSystem:emit"

m (Add link to getter of buffer size.)
m (Woops)
 
(2 intermediate revisions by 2 users not shown)
Line 13: Line 13:
 
== Examples ==
 
== Examples ==
 
=== Spawn a bunch of particles ===
 
=== Spawn a bunch of particles ===
This example will create a burst of particles when the spacebar is pressed. You can use the [https://www.love2d.org/w/images/9/9b/Love-game-logo-256x256.png löve logo] as an example image.
+
This example will create a burst of particles when the spacebar is pressed. 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:setLinearAcceleration(-5, -5, 50, 100); -- Randomized movement towards the bottom of the screen.
+
psystem:setLinearAcceleration(-5, -5, 50, 100) -- Randomized movement towards the bottom of the screen.
psystem:setColors(255, 255, 255, 255, 255, 255, 255, 0); -- Fade to black.
+
psystem:setColors(255, 255, 255, 255, 255, 255, 255, 0) -- Fade to black.
 
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
  
 
function love.keypressed(key)
 
function love.keypressed(key)
if key == ' ' then
+
if key == 'space' then
 
psystem:emit(32)
 
psystem:emit(32)
 
end
 
end
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::ParticleSystem]]
 
* [[parent::ParticleSystem]]

Latest revision as of 12:41, 2 October 2016

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Emits a burst of particles from the particle emitter.

Function

Synopsis

ParticleSystem:emit( numparticles )

Arguments

number numparticles
The amount of particles to emit. The number of emitted particles will be truncated if the particle system's max buffer size is reached.

Returns

Nothing.

Examples

Spawn a bunch of particles

This example will create a burst of particles when the spacebar is pressed. 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:setLinearAcceleration(-5, -5, 50, 100) -- Randomized movement towards the bottom of the screen.
	psystem:setColors(255, 255, 255, 255, 255, 255, 255, 0) -- Fade to black.
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

function love.keypressed(key)
	if key == 'space' then
		psystem:emit(32)
	end
end

See Also


Other Languages