I have this arraylist:
// Add predators
predators = new ArrayList();
for (int i = 0; i < predNum; i++) {
Creature predator = new Creature(random(width),
The draw()
function is called 60 times per second, so that's the loop you would be using. The frameCount
variable is incremented automatically each time draw()
is called.
Like The Coding Wombat said, you can use the modulo operator to determine when a variable (like frameCount
) is a multiple of a value (like 500
).
You can combine those ideas to do something once ever 500 frames:
ArrayList predators = new ArrayList();
void setup(){
for (int i = 0; i < predNum; i++) {
Creature predator = new Creature(random(width), random(height), 2);
predators.add(predator);
}
}
void draw(){
if (frameCount % 500 == 0){
predators.remove(predators.size()-1);
}
//draw your frame
}