I am trying to create bubbles simulation. I want a bubble to appear every 1-2 sec. and to burst at the bottom of the canvas.
I have this so far: https://codepen.io/Avivtech/pen/yLbKooV
I can not get to create only few bubbles…
When I move the
for loop to the
draw function it creates A LOT of bubbles
You can also check whether a balloon has left the screen and then give it a new y position
OR you remove balls when they left and when the number is smaller 30 use push
Thank you for the reply!
My problem is with creation of bubbles - how to constantly create bubbles on a very slow pace
Give this a try in draw():
if( frameCount%60 == 0 ) particles.push(new Particle()); //This will add one every 60 frames which is around 1 sec.
Look up the modulo (%) operator to understand how this works.
This is a useful function and worthy of exploration!
There are other ways to time events.