Hi,
I'm trying to implement a menu into my simple game. All I am trying to do is to have this rectangle displayed with some text, and when the mouse is pressed, the rectangle disappears and the program goes to the game.
I tried a few different methods. First off, I suspended the loop using noLoop(), because having void loop going and doing all of the different things for the game disrupted my menu. So I thought I would suspend, and so an if statement like this: (menu_condition is initialized to true);
if (menu_condition)
{
menu();//draw the menu
noLoop();//pause the loop
if(mousePressed)
{
//if we pressed the mouse, than we resume the loop and we no longer enter into menu for the rest of the game
//because menu_condition is set to false
menu_condition = false;
loop();
}
}
However, the problem with this is that we are not looping, so even though we are clicking the mouse, the void loop is paused so the mousePressed is not being registered. I tried doing a while loop instead of "if", and that would freeze. I tried implementing this condition during the loop, but this caused a lot of problems, so it seems to me that keeping the loop static is one of the only ways of effectively doing this (I'm most likely wrong)...
The menu() function just draws a rect with some text...nothing else.
How can I successfully incorporate this menu?
Here is my full void and setup functions:
void setup ()
{
minim = new Minim(this);
cue_stick_hit = minim.loadSnippet("stick_cue_hit.wav");
ball_wall_collision = minim.loadSnippet("ball_wall_collision.wav");
size(900, 600);//size of processing display window
frameRate(60); //Sets refresh rate of processing window
cue.rad = 31.0;//diameter
cue.col = #e2e9f0;//colour of cue ball
}
void draw ()
{
table ();
cue();
stick();
position.add(velocity_cue);
checkBoundaryCollision();
velocity_cue.mult(friction_factor);
velocity_check();
in_the_pocket();
if(boolean_condition == 1)
{
noLoop();
}
textSize(14);
fill(text_color_r,text_color_g,text_color_b);
text("POWER:"+power_percentage+"%", 100,100);
if (menu_condition)
{
menu();
noLoop();
if(mousePressed)
{
menu_condition = false;
loop();
}
}
}
Thank you!