V!nc3r Posted June 17, 2016 Share Posted June 17, 2016 Is it possible to set a startColor for particles ? I know there is color1, color2 & colorDead, but i want to avoid the "pop" when a particle is emit, and for that i want to set a full transparent color, which gradually switch to color1 & color2. Also, it could be cool to tell a particle that its size change over time (become bigger or smaller), i don't know if this option exist. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 17, 2016 Share Posted June 17, 2016 Hello! The idea to apply your changes could be to provide your own updateFunction. http://doc.babylonjs.com/tutorials/Particles#custom-functions Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted June 17, 2016 Share Posted June 17, 2016 Yes yes. On intialize you can create a time member and fill it and decide what to do over time. var timeInSec=var time = new Date().getTime()/1000; You can add that to each particle. p.timeInSec=var time = new Date().getTime()/1000; on initialization. When you do the update you can decide what you want have happen. Maybe alter the scale over time? Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted June 23, 2016 Author Share Posted June 23, 2016 Ok thanks. These are kind of things that scared graphist usually ahah Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 25, 2016 Share Posted June 25, 2016 Hi guys. Let's take a look at some custom particle functions. http://www.babylonjs-playground.com/#WQBB3#4 Right after I create the PS particle system in line 49, I set the customUpdateFunc in line 50. After that, myupdateFunction is used for updating... instead of the default one. In myupdateFunction, I no longer use color1, color2, and colorDead, and instead just make the particles change to a different random color each update cycle (lines 36-38). Notice in lines 28 and 29 that each particle has an age and lifeTime properties, by default. A simple if (particle.age > ???) {...} could easily be used in your custom update func. Let's look at a standard default update function... https://github.com/BabylonJS/Babylon.js/blob/master/src/Particles/babylon.particleSystem.js#L99 . Notice that a value called _scaledUpdateSpeed is used heavily... and that might be a helper for you, too, @V!nc3r. My demo goes a bit further, and also uses a customStartPosition function, too. (lines 58-148). This is how I accomplished 24 emitters. Notice that the installation of the startPositionFunction is not done the same (no line 50 for startPositionFunction)... so you must name your "override" function... startPositionFunction. But I could have also done ps.startPositionFunction = myStartPositionFunction... and that would have worked, too. All in all, study this playground a bit, and in no time, you will be making custom/override functions for our standard and SPS particle systems... with good success. Party(cle) on! Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted June 25, 2016 Share Posted June 25, 2016 Very interesting question, What i personally did, was that i made the particalsystem a "child" of the emitter, the emitter is then stored in an array of emitters (containing all emitters & particalSystems of my scene) var emitter = []; //function that creates a new emitter & particle system.. i don't have long so, need to get to work, so i'll only post critical points. emitter[id].particleSystem = new BABYLON.ParticleSystem("particles", 2000, scene); I then added a specific "updateType"(custom) Id to the particle system depending on what it is and what i want to change over time. emitter[id].updateType = 1; in my case 1 is for adding a "tail" to a moving ball of fire.(reducing the size of each particle as it gets older) I then go though each emitter in the renderLoop, check the updateType and for updateType === 1, i reduce the size of the particles as they grow older . particles can be accessed from emitter[id].particleSystem.particles. try to make a PG and play around with it, console.log to see what's what have fun and good luck! hopefully this added another idea of how to work with particles. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.