Confetti effect ?

Hello everyone

I would like to create an animation like that of this video: https://www.youtube.com/watch?v=Fg0V2w7gUw8 (time 0:24 - 0:30).

I’m mostly interested in the pignata that afterwards puts confetti in a very realistic way. Does anyone have any idea?

1 Like

Hi, you could perhaps use a particle effect for it?

Our software Radiance can be of help if you don’t want to do it all in code.

https://marketplace.coronalabs.com/asset/radiance-particles-effects-creator-v1-42

Otherwise, its using sprites and some advanced motion with random algorithm

Thank you

For the confetti I think it is excessive, I keep it in mind for another idea.

I would prefer something casual only that I can not give it that realistic effect

There is a free online particle generator (you’ll need to have flash installed) here, but I can say that Radiance is a brilliant piece of kit and is well worth it especially if you’re planning on writing more games.

Looking at the effect, there are two parts, there are the confetti parts that explode away from the pignata and then there are ones that fall from the top.

For the explosion, you could generate 20-30 individual pieces of confetti and give them a physics body and apply a linear impulse to them at a random angle away from the pignata and you can also apply some torque to them to give them spin. Vary the amount of force so some speed away, others will not go as far and look like they are falling.

Now for the ones falling from the top, generate how many of them at a random X value and off screen vertically (.y = -20 or so). Give them physics bodies so they will fall. You might want to vary the graphics scale for each so they fall at different rates. You can also give each one a Runtime enterFrame listener that will randomly apply a different torque every few hundred milli-seconds to get that back and forth motion. That enterFrame listener can also check their .x and .y to see when they are off the bottom or sides of the screen to remove them.

Rob

@Appletreeman Thanks, I saw the generator is very useful!!! It might be interesting to also take Radiance

@Rob Miracle Thank you very much for trying to do something like that. I think though in this case the physics might conflict with other elements (but with filters settle at all instant), rather since you talk about a function at runtime i wonder if it is not better at performance level avoid using physics and Just add something to that control…

You can stop the confetti to conflict with other bodies by setting the property isSensor to true or setting the filters for each object correctly.
And you can also achieve this with the transition library if you don’t want to use physics

Hi @maximo97,

It’s important to make the distinction between visual particles which are output by display.newEmitter(), and physical “particles” which are part of the LiquidFun framework revolving around display.newParticleSystem().

If you want the confetti to interact with other physical objects, you’ll need to attempt setting up the latter (LiquidFun). If the confetti just needs to be a visual effect, then you should use the standard particle emitter.

Brent

Well, thanks to all the advice. Now I should succeed

Hi again,

On a sidenote, I have not yet made any games where I’ve used physics.

It’s more a habit i think but just wanted to let you know that there are more than one way of doing things.

If I’d opt not to use particle effects, I’d probably use a sprite pool, some timers, transitions and the onFrame listener to achieve that pinata effect. Not much different from what Rob descriped, except no physics.

Good luck with your project!

Anaqim

Thanks again.

I want to understand one thing, the particle effects are very heavy? I ask why I avov in mind to use them for other games and I would like to know how it is their expense

Hi,

“particle effects” sound very advanced but are just a premade behaviour code that draw a lot of small sprites.

From my own tests, performance seems to be linked to how much texture memory and draw calls you are using.

It doesn’t matter is it means drawing a sprite, playing a sprite animation or drawing sprites using the particle engine (code).

I’d say that using particle effects is in most cases more efficient and lighter since you can draw many object that change in size etc over time, without any overhead from drawing “blank space” between pixels.

I might be arrested on this by those who are more knowledgable regarding draw calss and such, but this is how it seems to me.

I learned a lot while creating Radiance Particle Editor :slight_smile:

Take care!

Anaqim

Thanks again

I was doing a try with Rob’s advice, to give the confetti a boost every few seconds inside the runtime listener I have to use a random number like this:

 local function test() for i = #confettis, 1, -1 do if(random(1,100) == 5) then confettis[i]:applyLinearImpulse( 0, 1, confettis[i].x, confettis[i].y ) end end end Runtime:addEventListener( "enterFrame", test )

Or is there a better way?

i dont know if its the more optimized way of using the onFrame event but the logic looks fine to me

Rob probably know more.

Anaqim

To optimise…

    local function test()         for i = 1, 5 do             local confetti = confettis[math.random(1,#confettis)]             confetti:applyLinearImpulse( 0, 1, confetti.x, confetti.y )         end     end     Runtime:addEventListener( "enterFrame", test )

This way you randomly choose 5 elements and you are not looping them all and then doing a random check.

@anaqim, emitters are handled directly by the framework and as such will always be optimal.  User code (as shown above) is not always optimal.  Saying that, you can create sub optimal emitters by using too many particles.

@Sphere Game Studios, Thanks
But I do not think it’s okay as confetti get out of the screen and then delete it with your code in the end there would be a lot of problems …

Just add static objects on the boundary and use collision to remove confetti that goes off screen.

@Sphere Game Studio

Are you saying that the number of articles can start to cost alot even if the sprite sizes are small?

My tests so far has shown that sprite size is what cost.

The only way I see that happening is using a really high number, perhaps in the thousands, on a relative small screen area.

In such a case a sprite animation is probably more efficient, though seldom as nice.

Of course, as always when making anything for the mobile platforms, optimizing effect parameters is mandatory.

A sun can use both 50 and 250 particles and still look more or less the same.

Anaqim

Yes, number of particles can really drag performance if you have hundreds of them.

There are two main limitations… Size of graphics and number of graphics. You can hit a limit on one or the other or both.

Corona simply sends a list of instructions and textures to the GPU. Obviously the longer the list the slower this will run.

An easy win is less particles but larger texture.

Thanks for the tip

Have a great day!

Anaqim