We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello dear community, First of all, I'd like to excuse for any English mistakes I make, because I'm from switzerland ;).
Well, about a week ago we started to learn Processing 2.1 in our school, enthusastic as I am I wachted some tutorials at home and planned to do a little game, a simple Ping-Pong game.
I have designed a main menu, where you can select between "Start game", "Settings", and "Exit". I have already programmed the start- and the exit-button, like this (I have shortened it a bit for a more viewable sight):
void button () {
if ((mouseX >= xPos) && (mouseX <= xPos + xSize) && (mouseY >= yPos) && (mouseY <= yPos + ySize)) {
colr = color(80,80,80);
if (mousePressed) {
doAction = true;
}
}
noStroke();
fill (colr);
smooth();
rect (xPos, yPos, xSize, ySize, rectRound);
textFont (buttonFont, fontSize);
fill (textColr);
textAlign(CENTER);
text (text, xPos + (xSize/2), yPos + textyShift);
if (doAction) {
startGame();
}
}
However, in the startGame() function I have written a background(0);, because I read in some other posts that this will erase everything on the screen. But this is not true haha, when I click on "Start game", the background turns black, the "Start game"-butten disappears, but the ones for settings and exit still stay on the screen.
I have no idea what to do to make them disapper, and I hope someone can help me :).
Have a nice day everyone, fre3zr
Answers
A
background(0);
, or even clear(), indeed clears whole canvas w/ black color!We do that in order to get a clean slate to render animated graphics in different positions w/o having traces of previous 1s.
Well, if you keep redrawing them, of course they will stick on! :-&
You gotta have state flags to denote which is drawn or not!
So, when program starts, it gotta display its menu. So
state = MENU_STATE;
.Now, when the action starts, you change state to PLAY_STATE. And so on! :P
Of course, you gotta make all of the pieces of your program to obey that state variable! L-)
Some performance bits: (:|
If your program has the same smooth(), textAlign(), textFont() throughout, place those within setup()!
Oooh that opens new possibilites . haha :D
Thank you so much, I was really wondering about if there is a way to pause functions. :)
Oh, and with your answer to my first question, the next comes up. ^^
I don't understand how to use those static int states. I have declared a "static final int MENU_STATE = 0;" and a "static final int PLAY_STATE = 0;" at the top of the program, now how can I give those states to my different functions?
Have I to define each function with "static int state = MENU_STATE;" and then call the MENU_STATE in my draw() function or what?
Because I'm new to that language and it's the first language I try to use more detailled, and because I'm not very into OOP yet, it's quite difficult for me to understand haha, sorry for that!
With kind regards, fre3zr