Particle System Problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
evolvedpikachu
Prole
Posts: 1
Joined: Sat Nov 09, 2013 6:44 pm

Particle System Problem

Post by evolvedpikachu »

This won't create particles on the screen for some reason. I'm new to this, did I miss anything? There are no errors.

Code: Select all

function love.draw()
x, y = love.mouse:getPosition()
image = love.graphics.newImage("Electisock.png")
particlesystem = love.graphics.newParticleSystem(image,100)
particlesystem:setLifetime(5)
particlesystem:setSprite(image)
particlesystem:setSizes(10,15,12,8)
particlesystem:setPosition(x+math.random(-10,10),y+math.random(-10,10))
particlesystem:start()
particlesystem:update(0.1)
end
Last edited by evolvedpikachu on Sat Nov 09, 2013 9:11 pm, edited 1 time in total.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Particle System Problem

Post by Roland_Yonaba »

There are a few problems with this.
First of all, create the image once, outside the draw loop. Better, do it in love.load callback.
Second, the update method should be called in love.update callback, to be updated every frame.
Third, you might want to make use of setEmissionRate()
Fourth, you forgot to draw it.

Code: Select all

local image, particlesystem

function love.load()
  image = love.graphics.newImage("Electisock.png")
  particlesystem = love.graphics.newParticleSystem(image,8)
  particlesystem:setEmissionRate(3)
  particlesystem:setParticleLife(5)
  particlesystem:setSizes(1.0, 0.8, 0.4, 0.1)
  particlesystem:start()
end

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

function love.draw()
  love.graphics.draw(particlesystem,100,100)
end
And in case you want to set the position of it where you are clicking with the mouse, make use of love.mousepressed callback.

Code: Select all

function love.mousepressed(x,y,button)
   particlesystem:setPosition(x+math.random(-10,10),y+math.random(-10,10))
end
Hope this helps.

Note: We have an etiquette which recommends to use code tags when posting code.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests