Page 1 of 1

Particle System Problem

Posted: Sat Nov 09, 2013 6:53 pm
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

Re: Particle System Problem

Posted: Sat Nov 09, 2013 7:44 pm
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.