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?

1 Like

int counter; before setup

Then just say counter ++;


Now with the timer:

just say int timer; before setup

In setup timer=millis();

Then say in draw()

if(millis () - timer > 2000) {


show text

showText Would be a boolean variable

When the mouse is pressed: showText=true;

also in draw()


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;

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
  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!";
  else if (dist(mouseX,mouseY,posX,posY)>200)
    else if (dist(mouseX,mouseY,posX,posY)>125)

    else if (dist(mouseX,mouseY,posX,posY)>50) //initial if statement for the hot circle around the mouse 
1 Like


Didn’t you like my reply?

So why start a new thread…?

1 Like

Just implement what I told you

1 Like

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

1 Like

At the beginning of mousePressed

set the boolean true

1 Like

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

1 Like

Then use the timer to control your boolean showText

1 Like

thank you!

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

1 Like

Oh I see what you mean


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().

1 Like

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

1 Like

Maybe you can post your result here in a nice way

1 Like