I am printing objects from an array outputting 8 image objects using a for loop, the code works without draw() method, but when I include it, only the background image is shown.
How do I call the draw method in the setup method to work?
public class FishPAppletTest {
private static PApplet processing; // PApplet object that represents the graphic interface of the JunglePark application
private static PImage backgroundImage; // PImage object that represents the background image
private static Fish[] fishes; // fishes object, reference to perfect size array storing fish objects in the fish tank. These fish can be of different species.
private static Random randGen; // Type random constructor when new, Generator of random numbers
public static void main(String[] args) {
Utility.startApplication();
System.out.println(fishes[0]); //null because it is not stored?
}
/**
* Defines the initial environment properties of this application
* @param processingObj a reference to the graphic display window of this application
*/
public static void setup(PApplet processing) { // PApplet is kept, processing is the variable as input
backgroundImage = processing.loadImage("images/background.png"); // loads image in background
fishes = new Fish[8];
processing.image(backgroundImage, processing.width / 2, processing.height /2); // draw background image
}
/**
* Draws and updates the application display window.
* This callback method called in an infinite loop.
*/
public static void draw() { // called by utility class
for (int i = 0; i < fishes.length; i++) {
fishes[i] = new Fish(processing, processing.width / 2, processing.height / 2);
randGen = new Random(); // WORKS UP
int x = randGen.nextInt(processing.width);
int y = randGen.nextInt(processing.height);
fishes[i] = new Fish(processing, x, y);
fishes[i].draw();
}
}
}