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 › Turn on/off image visiblity
Page Index Toggle Pages: 1
Turn on/off image visiblity (Read 494 times)
Turn on/off image visiblity
Mar 2nd, 2010, 6:05pm
 
Hello all,

So I'm trying to figure out how to make it so in my program below the image I'm using for my start button dissapears after it is clicked. I want the user to click the button and everything that is on the screen gets cleared so that I can then draw the new stuff on the screen that I want.

I've tried using setVisible() and isVisible() but I don't know if that works with PImage or only PShape. Also I don't even know if I used it correctly.

Below is my code, any help would be appreciated.
Code:
PFont myFont;

void setup()
{
 size(500,500);
 background(0,0,0);
 smooth();
 
 myFont = createFont("Verdana", 24);
 textFont(myFont);
 
}

void draw()
{
 drawIntro();
 startButton();
}

void startButton()
{
 //load startButton image
 PImage start;
 start = loadImage("START.jpg");
 start.setVisible(true);
 image(start, 180, 360);
 
 //check if button is hovered over
 if(mouseX > 180 && mouseY > 360 && mouseX < 324 && mouseY < 432)
 {
   //check if button is pressed
   if (mousePressed == true)
   {
     start = loadImage("START2.jpg");
     start.setVisible(false);
     image(start,180,360);
       if(start.isVisible() == false)
         {
           background(0,0,0);
         }
   }
 }
}

void drawIntro()
{
 noStroke();
 fill(0,255,0);
 text("Processing's Box of Wonders!", 75,100);

}


Re: Turn on/off image visiblity
Reply #1 - Mar 2nd, 2010, 7:03pm
 
Have a boolean "started" global variable...

boolean started=false;

and then in draw(),

put if(!started)  startButton();

When the button is clicked, started is then set to true....
You shouldn't need setVisible...

Page Index Toggle Pages: 1