I'm trying to use threading to make it so I can display a "loading screen" while something is loading. The main class will draw the loading icon and start a thread to have the Menu Screen start initializing all the images it needs, and when the Menu Screen is done loading everything, it sets a global Done Loading variable to true, and the main class starts drawing it.
But how do I call MenuScreen.initialize() with thread()? It gives me an error in the console that says "There is no public MenuScreen.initialize() method in the class MainClass".
Here's a trimmed version of what I have so far. The main class:
import gifAnimation.*; // used for the loading icon
Screen curScreen;
boolean doneLoading;
Sprite loadingGif;
void setup()
{
size(600, 600);
frameRate(30);
loadingGif = new Sprite(this, "loading flower.gif");
doneLoading = false;
curScreen = new MenuScreen();
thread("MenuScreen.initialize");
}
void draw()
{
background(50);
if(doneLoading) curScreen.screenDraw();
else loadingGif.drawThis(width - 60, height - 60);
}
And the MenuScreen class, which implements a very simple Screen interface that stipulates its initialize() and screenDraw() methods:
class MenuScreen implements Screen
{
int curSelection; // which selection item the cursor is on right now: new game, load game, etc.
PImage backgroundImg;
PImage cursorImg;
MenuScreen()
{
}
void initialize()
{
backgroundImg = loadImage("WelcomeBackground.png");
cursorImg = loadImage("WelcomeCursor.png");
doneLoading = true;
}
void screenDraw()
{
image(backgroundImg, 0, 0, width, height);
text("Herro wuorld", 50, 50, 200, 200);
}
}
I've also tried using thread("initialize") in MenuScreen's constructor, but that tries to look for an initialize function in the main class, too. I suppose I could just make the Initialize function a global function, but that doesn't seem like optimal coding standards when all I should need is a proper String for my call to thread()...