We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Pause: keyPressed() .. keyReleased()
Page Index Toggle Pages: 1
Pause: keyPressed() .. keyReleased() (Read 1796 times)
Pause: keyPressed() .. keyReleased()
May 13th, 2007, 7:49am
 
Is there a problem with keyReleased() ?

keyPressed() is colored red in the editor,
but
keyReleased() is NOT colored red in the editor. Why ?

How to pause the execution of a program ?

To pause/resume by pressing/releasing 'z',
is the following section of code OK ?

void keyPressed() {
 if (key == 'z' || key == 'Z') {
   noLoop();  
 }
}

void keyReleased() {
 if (key == 'z' || key == 'Z') {
   loop();  
 }
}

Is there be a better way ? a simpler way ?

Thanks if you can help..
Re: Pause: keyPressed() .. keyReleased()
Reply #1 - May 15th, 2007, 8:35pm
 
Hi,

You could check these kind of questions with "print" or "println".

Don't know yet how to get a nice box around code...

Code:

void setup() {
}

void draw() {
 println("check certain things first; use \"print\"");
}

void keyPressed() {
 //code in draw should not be executed
 noLoop();
}

void keyReleased() {
 //code in draw should be executed
 loop();
}

Good luck with your proce55ing adventures!

/BEnm
Re: Pause: keyPressed() .. keyReleased()
Reply #2 - May 23rd, 2007, 8:02am
 
Hi! Well, on the game i am creating, i've actually created its own little pause menu, with images, boxes, text and code.

Basically, to pause the menu you can create a boolean...

Code:

boolean pause = false;

void setup()
{
size(640, 480);
frameRate(50);
}

void draw()
{
if(pause == true){
background(0);
}else{
background(255);
}
}

void keyPressed()
{
if(keyCode == ENTER){
if(pause == false){
pause = true;
}else{
pause = false;
}
}
}


If Its paused, it will make the background black, if its unpaused, it will turn the background white.

If you wish to continue developing on this, its easy enough to add boxes, menu's and even images. On my pause menu i have a series of images, which i have worked out the code for so when you hover over the image, it changes the image to another image, which is the same, but has a different colour. This then looks like a rollover and adds effect.

Thanks,
Steve.
Page Index Toggle Pages: 1