Reputation: 11
For my AP Computer Science class, I am making a Pokemon personality quiz that has you answer a couple of questions and gives you which Pokemon you are the most like. We had just learned Processing, and the end of the year project is to make a program that utilizes what we learned. So, for my personality quiz, I have code that runs in the eclipse console, and I have the player answer a couple of questions, and I keep track of their answers. Different answers give a tally to different Pokemon and at the end of the program, the Pokemon you are most like is the one with the most tallies. However, to incorporate processing, I wanted to have a picture of the Pokemon and its sound effect appear once the quiz was completed. Unfortunately I was unable to figure out how to do such a thing. Is there anything I can do?
Upvotes: 1
Views: 65
Reputation: 3800
You can delay the launch of Processing like so. You can perform the quiz and then create & run an instance of your Processing Class (here named PokemonSketch). How you pass the information from the quiz to the PApplet instance is up to you.
public static void main(String[] args) {
//Quiz Code
//Quiz Code
//Quiz Code
PokemonSketch sketch = new PokemonSketch();
PApplet.runSketch(new String[]{""}, sketch);
}
Here, the PApplet is run immediately and the quiz done within setup()
.
First initialise your sketch in Processing's FX2D rendering mode in the call to size():
@Override
public void settings() {
size(x, y, FX2D);
}
Now we can hide the window at launch, perform the quiz, and show the window upon completion (Processing will then run the draw loop).
@Override
public void setup() {
final PSurfaceFX FXSurface = (PSurfaceFX) surface;
final Canvas canvas = (Canvas) FXSurface.getNative();
final Stage stage = (Stage) canvas.getScene().getWindow();
stage.hide();
final Scanner reader = new Scanner(System.in);
System.out.println("Enter a number: ");
final int n = reader.nextInt();
reader.close();
stage.show();
}
Upvotes: 1