How to add to an ArrayList every x seconds?

void setup(){
jellies = new ArrayList();
for(int i=0; i<=5; i++){
jellies.add(new Jellyfish(random(0, 800), random(height), random(-40, 40), random(0.05, 0.35)));
}

for(int i = jellies.size()-1; i>=0; i–){
Jellyfish jellyfish = jellies.get(i);
jellyfish.display();

}

if(millis()-timer>=2000){
jellies.add(new Jellyfish(random(0, 800), 850, random(-40, 40), random(0.05, 0.35)));
timer=millis();
}

The above is just part of the code. I would like to display a new jellyfish coming from the bottom of the screen every 5 seconds. At first it works but after a while they start popping in the middle of the screen and stop completely.

Thanks!!

Hello,

A good place to start:

Click here for resources

I encourage you to look at the resources available here:

Beginner

Advanced

Please format your code:
https://discourse.processing.org/faq#format-your-code

You need to understand some basic elements before you begin:

Check out out the tutorials, examples and references and there you will find what you need.

Get a basic timer working first and then use that to add to the ArrayList.

:)