hello,
welcome in the forum!
That's called state of a program.
Your program could be in state title screen or in state play or in state show help screen.
Store the current state in a variable "state".
When you are in the title screen and the user clicks the mouse, you want to change the variable to state play, or whatever you call it.
Depending on the value of the variable different things happen in draw().
Note that I gave the different states numbers and those names.
Example:
- // -------------------------------------------
-
- // program
- final int statePlay =0;
- final int stateWon =1;
- final int stateDead =2;
- final int statePause =3;
- final int stateStartUp =4;
- final int stateNewLevel =5;
- //
- int stateOfGame = stateStartUp;
- //
- void setup () {
- }
- void draw() {
- // this runs on and on
- background(0);
- // depending on stateOfGame
- switch (stateOfGame) {
- case stateStartUp:
- showTitleScreen;
- break;
- case statePlay:
- playGame;
- break;
- case default:
- // shouldn't get here / Error
- println("Error 29 with " +
- stateOfGame +
- ".");
- // exit program
- exit();
- break;
- } // switch
- } // func
And then you need to program the functions showTitleScreen, playGame and mousePressed()
- void showTitleScreen() {
- background(0);
- text ( "click anywhere to continue." , 30,100);
- }
- void playGame () {
- background(0);
- text ( "Play game." , 30,100);
- }
- void mousePressed() {
- state=statePlay;
- }
If you think this further, in the function mousePressed()
you as well want such a switch-statement like in draw(), because in the title screen,
a mouse click just changes the state, whereas in the state play
mouse can shoot or aim - totally different behaviour.
When the player lost, you can return the state to the title screen.
Greetings, Chrisir
P.S:
You can place the camera with camera() in 3D space but that's a different thing. It's about looking at a 3D scene or so.