Creating a frame timer

I am trying to create a timer that makes an ellipse disappear 2 seconds or 120 frames after the mouse has been pressed, the ellipse and text appear whenever i press my mouse, but they disappear far too fast about 1 frame after so i was wondering how i would make it so that they stay on the screen for 120 frames with my if and else if statements. also another question is how would i create a counter for how many times my mouse has been clicked on the screen before i click on the object i am trying to find?

int counter; before setup

Then just say counter ++;

Timer

Now with the timer:

just say int timer; before setup

In setup timer=millis();

Then say in draw()

if(millis () - timer > 2000) {
    timer=millis();
    showText=false;
}

——————————

show text

showText Would be a boolean variable

When the mouse is pressed: showText=true;

also in draw()

if(showText)
    text("test",111,111);

This would show the text for 2 seconds

i am trying to make a hot and cold game and have the circles that say if I’m cold or not appear when i click and i have all of that completed, but i want them to disappear 2 seconds or 120 frames after i have clicked every time and have a counter for how many times i have clicked. i was wondering if i could get any help as i am completely stumped and cannot figure it out. the circles will disappear from around my mouse in 1 frame by the looks of it but I want them to last for 120 frames. I also apologize in advance for how horrible my code is and how badly formatted it is as I am very new to coding

final int ballDiam = 30; //diam of the randomly occuring invisible ball
float posX; //decloration of the X position of the random ball 
float posY; //decloration of the Y position of the random ball
final int coldDetector = 400; //diam of the cold circle
final int warmDetector = 250; //diam of the warm circle
final int hotDetector = 100; //diam of the hot circle
final int hotColor = color(255,0,0); //color of the hot circle
final int warmColor = color(255,100,0); //color of the warm circle
final int coldColor = color(0,0,255); //color of the cold circle 

float textWidth = width/2;
float textAscent = 10;
float textDescent =2 ;
boolean mouseClicked = false;
int timer;
int counter;


//setup 
void setup()
{
 size(500,500); //size of the program
 posX = random(width); //properties of the random X location
  posY = random(height); //properties of the random Y location
  timer = millis();
  
}
//drawn fumctions
void draw()
{
  
  background(200); //background color
 //add stroke (stroke(200); when progrm is finished
  fill(200); 
  {
    stroke(0);
  ellipse(posX,posY,ballDiam,ballDiam); //random invisible ball meant to be found
  //hot circle
  }
}
  
  
  
  void mouseClicked() {
  
  if  (dist(mouseX,mouseY,posX,posY)>300 )
  {
  String F = "You're freezing!";
    textAlign(255,255);
    textSize(15);
    fill(0,30,255);
    text(F,255,255);
  }
  else if (dist(mouseX,mouseY,posX,posY)>200)
  {
  noFill();
  stroke(coldColor);
  ellipse(mouseX,mouseY,coldDetector,coldDetector);
  }
    else if (dist(mouseX,mouseY,posX,posY)>125)
    {
      noFill();
      stroke(warmColor);
      

stroke(warmColor);
      ellipse(mouseX,mouseY,warmDetector,warmDetector);
  }
    else if (dist(mouseX,mouseY,posX,posY)>50) //initial if statement for the hot circle around the mouse 
  {
  noFill();
    stroke(hotColor);
    ellipse(mouseX,mouseY,hotDetector,hotDetector);
    
  }     
  }

??

Didn’t you like my reply?

So why start a new thread…?

Just implement what I told you

I did try, but I couldn’t get it to work so I made something with the code I currently have in case that makes things any easier I don’t know how this site works very well

At the beginning of mousePressed

set the boolean true

Then where you use text say if(showText) before it

Then use the timer to control your boolean showText

thank you!

but what do i do about the circle around my curser to make them stay as well

Oh I see what you mean

Apologies

So, best when you set a boolean showCircle in mousePressed to true

In draw act accordingly and say

if(showCircle) {
// show Circle 
}

After timer has passed set showCircle to false

So you want to do the drawing in draw() when prompted by the boolean that has been set to true in mousePressed().

ooohhh that makes sense

i should have worded my question better

thank you, yeah I’m trying to get it so i have text on screen and the circle around my mouse when clicked for 2 seconds

thank you for the help

Remember to hit ctrl-t in processing to get nice auto format prior to posting

Maybe you can post your result here in a nice way