Game Development Reference
In-Depth Information
Creating Effects
LÖVE comes prepackaged with particle effects, so you can create many spectacular effects in your
app or game, including smoke trails, fog, and snow.
To create particles, we need to create a particle emitter —a source that will emit a particle. Then we
need to set the parameters on what our particle is like (e.g., how fast it moves, its lifespan, how long
it takes to decay, what kind of particle is it, etc.).
function love.load()
img = love.graphics.newImage("part2.png")
p = love.graphics.newParticleSystem(img, 256)
-- This creates a new particle emitter that emits particles
-- with the image img and shall have a maximum of 256 particles.
p:setEmissionRate (20)
p:setLifetime(1)
p:setParticleLife(4)
p:setPosition(50,50)
p:setDirection(0)
p:setSpread(2)
p:setSpeed(10,30)
p:setGravity(30)
p:setRadialAcceleration(10)
p:setTangentialAcceleration(0)
p:setSize(1)
p:setSizeVariation(0.5)
p:setRotation(0)
p:setSpin(0)
p:setSpinVariation(0)
p:setColor(200,200,255,240,255,255,255,10)
p:stop()
end
function love.update(dt)
p:start() -- Create a particle burst
p:update(dt) -- Update the particle's position as required
end
function love.draw()
love.graphics.draw(p, 20, 0)
end
If you want to move the particle emitter with the mouse, you can simply change the love.update
function to the following:
function love.update(dt)
p:setLocation(love.mouse:getX(), love.mouse:getY())
p:start() -- Create a particle burst
p:update(dt) -- Update the particle's position as required
end
 
Search WWH ::




Custom Search