Thanks very much both of you!
Now I have that code in and what it's doing is drawing the ellipse in my Missile class for one frame, waiting two seconds, drawing the next frame, etc.
To be more precise, I have created an array of 40 "missile"s and a loop that calls moveMissile(); for the length of the array. This gives me 40 missiles flying across the screen at once.
This is what I had originally, just to test that my array worked:
- Missile[] missiles = new Missile[40];
- PImage bgImage;
- void setup()
- {
- size(640, 480);
- smooth();
- bgImage = loadImage("background.jpg");
- for (int i = 0; i < missiles.length; i++)
- {
- missiles[i] = new Missile();
- }
- }
- void draw()
- {
- image (bgImage, 0, 0);
- for (int i = 0; i < missiles.length; i++)
- {
- missiles[i].moveMissile();
- }
- }
That draws 40 missiles moving across the screen at once. Adding time and millis() into the mix:
- Missile[] missiles = new Missile[40];
- int time;
- PImage bgImage;
- void setup()
- {
- size(640, 480);
- smooth();
- bgImage = loadImage("background.jpg");
- for (int i = 0; i < missiles.length; i++)
- {
- missiles[i] = new Missile();
- }
- }
- void draw()
- {
- image (bgImage, 0, 0);
- for (int i = 0; i < missiles.length; i++)
- {
- if (millis() - time >= 2000)
- {
- missiles[i].moveMissile();
- time = millis();
- }
- }
- }
This is drawing one frame of moveMissile every 2 seconds instead of doing one complete moveMissile every 2 seconds.
Thanks very much for the help :)