Page 1 of 2

pausing a particle system and restarting it

Posted: Thu Oct 24, 2013 12:11 am
by Fatmat927
okay so i just began using the particle system and i had trouble with pausing i finally found out how to pause it but now i can,t make it start again so here is what i've done by now and this is just a practice i'm doing to eventually add it to my game

Code: Select all

local fireparticlesystem = love.graphics.newImage("fire for particle system.png")
local ps = love.graphics.newParticleSystem(fireparticlesystem, 25)

empty = ps:isEmpty()
ps:setEmissionRate(5)
ps:setParticleLife(5)
ps:setSizes(1)
ps:setLifetime(-1)

function love.load()
end

function love.draw()
	love.graphics.draw(ps, 380, 280, 0, 1, 1, 0, 0)
end

function love.update(dt)
	ps:update(dt)
	if ps:isActive() then
		if love.timer.getTime() >= 5 then
			ps:pause()
			if ps:pause() then
				if love.timer.getTime() >= 1 then
					ps:start()
				end
			end
		end
	end
end

Re: pausing a particle system and restarting it

Posted: Thu Oct 24, 2013 1:41 am
by Ref
Will probably get dinged for reposting file again but take a look at the code.
(Try the s,z,x keys.)

Re: pausing a particle system and restarting it

Posted: Thu Oct 24, 2013 2:18 am
by Fatmat927
now i was just wondering i think the problem is in the timers maybe they all run as one so it doesn't work would that be possible? and thanks for the file but it's not helping although i think i understand a bit more the particle system. and if the problem is the timers how could i fix this because i never really used the timers
actually i made some more test and it seems that whenever I add timers, I can't start it back again it just ignores it

[]

Posted: Fri Oct 25, 2013 7:51 am
by bekey
-snip-

Re: pausing a particle system and restarting it

Posted: Fri Oct 25, 2013 1:18 pm
by Lafolie
Yup, this is exactly what you should do. I've been toying with the particle system recently, here's a file you can test it out with (any keypress will toggle update).

Re: pausing a particle system and restarting it

Posted: Fri Oct 25, 2013 4:06 pm
by Fatmat927
that might worked but the problem is i want no particle when it is paused although the sample you gave me only made them stop moving but hanks for trying tho ^^

[]

Posted: Fri Oct 25, 2013 5:53 pm
by bekey
-snip-

Re: pausing a particle system and restarting it

Posted: Fri Oct 25, 2013 6:31 pm
by Nixola
ps:stop()?

Re: pausing a particle system and restarting it

Posted: Fri Oct 25, 2013 7:02 pm
by Fatmat927
Nixola, i tried the ps:stop() but then when i tried to ps:start() it didn't work
and i will try the same thing as the update but with the draw thanks I didn't thought about this

Re: pausing a particle system and restarting it

Posted: Fri Oct 25, 2013 9:19 pm
by Ref
Fatmat927 wrote:Nixola, i tried the ps:stop() but then when i tried to ps:start() it didn't work
and i will try the same thing as the update but with the draw thanks I didn't thought about this
Just look a my example above.
It uses start & stop without any problems.
Nixola's approach works just as well.
The difference is 'stop' will stop particles from being generated. The particles already created will disappear.
Preventing 'update' from occurring (Nixola's approach) will just stop the generation of new particles and retain all the previously generated particles in their current positions.
Your problem should be solved!