pausing a particle system and restarting it

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Fatmat927
Prole
Posts: 42
Joined: Wed Sep 18, 2013 1:15 am

pausing a particle system and restarting it

Post 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
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: pausing a particle system and restarting it

Post by Ref »

Will probably get dinged for reposting file again but take a look at the code.
(Try the s,z,x keys.)
Attachments
particle.love
Simple particle script
(3.05 KiB) Downloaded 187 times
Fatmat927
Prole
Posts: 42
Joined: Wed Sep 18, 2013 1:15 am

Re: pausing a particle system and restarting it

Post 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
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:08 am, edited 1 time in total.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: pausing a particle system and restarting it

Post 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).
Attachments
particles.love
(5.26 KiB) Downloaded 196 times
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Fatmat927
Prole
Posts: 42
Joined: Wed Sep 18, 2013 1:15 am

Re: pausing a particle system and restarting it

Post 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 ^^
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:08 am, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: pausing a particle system and restarting it

Post by Nixola »

ps:stop()?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Fatmat927
Prole
Posts: 42
Joined: Wed Sep 18, 2013 1:15 am

Re: pausing a particle system and restarting it

Post 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
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: pausing a particle system and restarting it

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests