Some problems with my score board...
in
Programming Questions
•
5 months ago
I'm trying to make a scoring system where there's a score for each team and a timer which starts from when the button is pressed (highlighted in the code with 'timer button' at line 30, as a comment). I have two problems at the moment: the plus buttons are only supposed to plus one to the score variables if the mouse is clicked in the rectangle. However, this doesn't happen (it does but something else also does), when you click outside the rectangle and then drag the mouse into it, it registers as a mouse click. How do I stop this? This is labelled at line 66 with //button clicked.
My second issue is that the timer's numbers keep appearing over the top of the last one, instead of the last second disappearing and the next one appearing on a black background. How can I solve this problem too? Also the timer only works when the mouse is over the button. (line 27-36).
- color fill1 = color(255,255,255);
- color fill2 = color(255,255,255);
- color text = color(0,0,0);
- color white = color(255,255,255);
- color yellow = color(255,255,255);
- int score = 0;
- int score2 = 0;
- boolean mymouse = true;
- int five = 5;
- int half = 1;
- boolean release;
- String team1 = "Score";
- String team2 = "Score";
- void setup(){
- size(400,400);
- }
- void draw(){
- teamScoreone(width*1, height*1, 10, 10);
- teamScoretwo(width*1, height*1, 10, 10);
- int time = millis();
- fill(255,255,255);
- // timer button
- rect(5,160,50,50);
- if (mymouse == true && mouseX > 10 && mouseX < 60 && mouseY > 160 && mouseY < 210){
- textSize(32);
- fill(0,0,0);
- text(time / 1000,5 , 220);
- }
- //half(width*1, height*1, 10, 10);
- //timer(width*1, height*1, 10, 10);
- }
- /*void mousePressed() {
- score++;
- score = score;
- }
- */
- void teamScoretwo(float xloc, float yloc, int size, int num){
- fill(white);
- rect(140,100,110,50);
- textSize(32);
- fill(0,0,0);
- text(team1, 10+130, 90);
- text(score2, 30+130, 140);
- fill(0,0,0,0);
- rect(5+130,5,120,150);
- //button clicked
- if (mymouse == true && mouseX > 10+130 && mouseX < 60+130 && mouseY > 10 && mouseY < 60){
- fill1 = yellow;
- score2 = score2 - 1;
- mymouse = false;
- }
- else{
- fill1 = color(255,255,255);
- }
- if (mymouse == true && mouseX > 70+130 && mouseX < 120+130 && mouseY > 10 && mouseY < 60){
- fill2 = yellow;
- score2 = score2 + 1;
- mymouse = false;
- }
- else{
- fill2 = color(255,255,255);
- }
- // plus button
- fill(fill1);
- rect(140,10,50,50);
- textSize(32);
- fill(0,0,0);
- text("-", 25+130, 45);
- // minus button
- fill(fill2);
- rect(70+130,10 ,50,50);
- textSize(32);
- fill(0,0,0);
- text("+", 85+130, 45);
- if (score2 <= 0){
- score2 = 0;
- }
- }
- //end of scoreboard two and start of score baord one
- //score board one
- void teamScoreone(float xloc, float yloc, int size, int num){
- fill(white);
- rect(10,100,110,50);
- textSize(32);
- fill(0,0,0);
- text(team2, 10, 90);
- text(score, 30, 140);
- fill(0,0,0,0);
- rect(5,5,120,150);
- //button clicked
- if (mymouse == true && mouseX > 10 && mouseX < 60 && mouseY > 10 && mouseY < 60){
- fill1 = yellow;
- score = score - 1;
- mymouse = false;
- }
- else{
- fill1 = color(255,255,255);
- }
- if (mymouse == true && mouseX > 70 && mouseX < 120 && mouseY > 10 && mouseY < 60){
- fill2 = yellow;
- score = score + 1;
- mymouse = false;
- }
- else{
- fill2 = color(255,255,255);
- }
- // plus button
- fill(fill1);
- rect(10,10,50,50);
- textSize(32);
- fill(0,0,0);
- text("-", 25, 45);
- // minus button
- fill(fill2);
- rect(70,10,50,50);
- textSize(32);
- fill(0,0,0);
- text("+", 85, 45);
- if (score <= 0){
- score = 0;
- }
- }
- void mousePressed(){
- mymouse=true;
- }
THANKS FOR YOUR HELP!!
1