How to make multiple instances of one loaded particle "distinct" from each other (solved)

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.
Post Reply
User avatar
Khranos
Prole
Posts: 30
Joined: Tue Aug 11, 2015 1:22 am

How to make multiple instances of one loaded particle "distinct" from each other (solved)

Post by Khranos »

To elaborate on the title:

I am currently working with the Löve particle system, and have run into a bit of a snag. I'm loading in the particles (in love.load), and am utilizing the same loaded particle system on multiple entities. It works as planned aside from the fact that the particles are synced among every entity using that specific particle type. I'm still not 100% sure if it's just part of the module or if it's in the way I'm using it. Included is a .gif of the issue:
Notice the particles are the exact same.
Notice the particles are the exact same.
crateSync.gif (275.2 KiB) Viewed 4464 times
One way I've thought to solve this issue is to create a function which creates a particle system each time I need to use it (each "crate" has its own number, just send that number to a function to create a new particle system complete with parameters appended with the number of the crate, i.e. silverParticleS##), then just trash collect the information whenever it's no longer needed. However, I'm worried that I will come to regret doing that for performance reasons later on.

I've scoured the wiki pages on the particle system for another way to deal with this issue. Is there a better way than what I've mentioned above? I appreciate any help that can be offered!


Edit: the below image displays what I'm looking to do better. Notice how the two different colour crates have a staggered emission time, whereas the same colour crates above have the same emission time, size, et cetera.
Each colour crate is using a particle system made for the specific colour.
Each colour crate is using a particle system made for the specific colour.
crateSyncExample.gif (349.65 KiB) Viewed 4396 times
Solution: for any future viewers with the same problem, particleSystem:clone() is the method to use. I created a function which added the clone and a unique identifier to a table, then iterated over that table in an update function. I then used the unique identifier to draw the clone in its specific location by matching the identifier with the object that needs the clones.
Last edited by Khranos on Wed Dec 21, 2016 1:25 am, edited 4 times in total.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to make multiple instances of one loaded particle "distinct" from each other

Post by s-ol »

Khranos wrote:To elaborate on the title:

I am currently working with the Löve particle system, and have run into a bit of a snag. I'm loading in the particles (in love.load), and am utilizing the same loaded particle system on multiple entities. It works as planned aside from the fact that the particles are synced among every entity using that specific particle type. I'm still not 100% sure if it's just part of the module or if it's in the way I'm using it. Included is a .gif of the issue:
crateSync.gif
One way I've thought to solve this issue is to create a function which creates a particle system each time I need to use it (each "crate" has its own number, just send that number to a function to create a new particle system complete with parameters appended with the number of the crate, i.e. silverParticleS##), then just trash collect the information whenever it's no longer needed. However, I'm worried that I will come to regret doing that for performance reasons later on.

I've scoured the wiki pages on the particle system for another way to deal with this issue. Is there a better way than what I've mentioned above? I appreciate any help that can be offered!
you need to create exactly one particle system per object. how could love possibly keep track of what which of the different invocations should look like?

You should probably not dynamically create the systems and garbage collect. Just assign them to your 'entity' when you create that and they will get destroyed with it (make sure not to leave any other references obviously).

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Khranos
Prole
Posts: 30
Joined: Tue Aug 11, 2015 1:22 am

Re: How to make multiple instances of one loaded particle "distinct" from each other

Post by Khranos »

s-ol wrote: you need to create exactly one particle system per object. how could love possibly keep track of what which of the different invocations should look like?

You should probably not dynamically create the systems and garbage collect. Just assign them to your 'entity' when you create that and they will get destroyed with it (make sure not to leave any other references obviously).
If I'm not mistaken, I think there's a slight misunderstanding -- I'm fine with all of the particles of said type looking the same, but I'm not okay with them being sent out at the exact same intervals, sizes, and speeds for each iteration I have on-screen.

Whether I use the same created particle system or create new ones as I go along, I don't particularly care as long as it isn't a code hazard. I've just included an example of more what I'm looking to do in the main post (assuming this was a misunderstanding).
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: How to make multiple instances of one loaded particle "distinct" from each other

Post by Positive07 »

Have you checked the wiki? I mean, there is a [wiki]ParticleSystem[/wiki] page, and there are lots of methods to change how the ParticleSystem behaves on the run, if you want more than one the [wiki]ParticleSystem:clone[/wiki] should help.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Khranos
Prole
Posts: 30
Joined: Tue Aug 11, 2015 1:22 am

Re: How to make multiple instances of one loaded particle "distinct" from each other

Post by Khranos »

Strange, I've looked through that page many, many times. It appears I've completely missed that method! I found it a bit odd that there wasn't a method to use the same system multiple times, so it's nice to know it did actually exist.

After rewriting the system and tons of trial and error, I now have a working particle system. I greatly appreciate the help!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to make multiple instances of one loaded particle "distinct" from each other

Post by s-ol »

Khranos wrote:Strange, I've looked through that page many, many times. It appears I've completely missed that method! I found it a bit odd that there wasn't a method to use the same system multiple times, so it's nice to know it did actually exist.

After rewriting the system and tons of trial and error, I now have a working particle system. I greatly appreciate the help!
it's not a clone of the original with it's own timing, I'm pretty sure it will look exactly the same still, unless it has a different seed. And it will still be the same as taking the same values and just making two, except you will probably end up keeping a unused master copy around to clone from.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Khranos
Prole
Posts: 30
Joined: Tue Aug 11, 2015 1:22 am

Re: How to make multiple instances of one loaded particle "distinct" from each other

Post by Khranos »

s-ol wrote: it's not a clone of the original with it's own timing, I'm pretty sure it will look exactly the same still, unless it has a different seed. And it will still be the same as taking the same values and just making two, except you will probably end up keeping a unused master copy around to clone from.
I'm only changing the seed upon loading the game, so I assume that the clone method has something built-in to change the seed. Each individual clone works independently of each other with a satisfying degree of randomness. Each cloned particle even begins in a different way than the last, fortifying the idea that there's something included in the method to modify each for that random feel.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 8 guests