Particle System Tutorial on Android Part 5

You can notice from the first couple of fountains that all the particles get generated at the start and then spawn after the time to live is up. This results in a massive blast at the start and then things start to get more evenly distributed. In this tutorial, the particles will get slowly released in to the system. This is actually fairly easy to do with only a new variable called activeParticles (set at zero) and few lines of code in the update method in ParticleSystem.java

// add the particles slowly
if (activeParticles < PARTICLECOUNT)
{
    // calculate how many particles per frame.  I have set
    // the particles per second at 100
    int addParticleCount = new Float(100f * timeFrame).intValue();
    // always be adding at least one particle
    if (addParticleCount < 1)
    {
    	addParticleCount = 1;
    }
    activeParticles = activeParticles + addParticleCount;
    if (activeParticles > PARTICLECOUNT)
    {
    	activeParticles = PARTICLECOUNT;
    }
}

The other feature added is a bounce when the particles hit the FLOOR. So instead of just stopping all speeds, we keep the x and y speeds intact and invert the Z speed. As well, cut the Z speed in half to have the particle not bounce as high as the previous height. The time to live can be extended to give that rolling look.

if (mParticles[i].z <= FLOOR)
{
    mParticles[i].z = FLOOR;
    // invert the Z speed and cut it in half so the bounce is not as high
    mParticles[i].dz = mParticles[i].dz * -.5f;
}

Again the code can be found on Google Code. The demo is also available on the Android Market, search for "Particle System" or scan the QR code below

8 thoughts on “Particle System Tutorial on Android Part 5

  1. Hola! Hablo espanol poco, pero…
    I just added a button to add this blog to Google reader on the sidebar.

  2. Great! :)
    But I think in the for loops in update and draw one needs to replace the condition from
    for (int i = 0; i < PARTICLECOUNT; i++) {
    to
    for (int i = 0; i < activeParticles; i++) {

    Am I right? :)

  3. Yep, Patrick you are right. I think my cut and pasting from the code is wrong. I’ll update the for loop to reflect what is checked into Google code. Thanks for catching that.
    Speaking of the code, I just looked at it checked in and bleach! I’m going to reformat the code and re-check it in. Looks like there are tabs mixed with spaces.
    Thanks for visiting

  4. I’m truly enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more
    pleasant for me to come here and visit more often.
    Did you hire out a developer to create your theme?
    Excellent work!

  5. Hey I know this is off topic but I was wondering
    if you knew of any widgets I could add to my blog that
    automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>