Im trying to make a program where you are a ship and you simply avoid comets that fly towards you. I somewhat know how to use array lists to add and subtract objects, but I'm not sure how to get the program to add and subtract objects after a specific time like 5 seconds. My goal is to make each comet spawn 2 seconds apart but I'm not sure how. If anyone can help please let me know!
Asked
Active
Viewed 377 times
0
-
Other than `frameCount` you can also look into [millis()](https://stackoverflow.com/questions/12417937/create-a-simple-countdown-in-processing/12421641#12421641). – George Profenza Oct 07 '18 at 15:55
1 Answers
0
Processing exposes a useful variable frameCount
that you can use for such timing behaviours.
You could use it in combination with the modulo operator % (an operator that returns the remainder after the division of two numbers), as follows:
draw() {
.
.
.
if (frameCount % t == 0) {
spawnComet();
}
.
.
.
}
Assuming frameRate
is fixed at 60, t
takes the value of 60*(desired time delay in seconds). You want to spawn comets every 2 seconds: 60*2 = 120. Therefore set t
to 120 to satisfy the requirement of your example. This means spawnComet()
will trigger every 120 frames.

micycle
- 3,328
- 14
- 33