# Creating a frame timer

**URL:** <https://discourse.processing.org/t/creating-a-frame-timer/18165>\
**Category:** Coding Questions\
**Created:** [February 26, 2020, 10:50pm UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165 "2020-02-26T22:50:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)\
**Post date:** [February 26, 2020, 10:50pm UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/1 "2020-02-26T22:50:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 26, 2020, 10:58pm UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/2 "2020-02-26T22:58:42Z")

</div>

> [@NotConsumable](#):
>
> how would i create a counter for how many times

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

```auto
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()

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

```

This would show the text for 2 seconds

---

<div class="post-metadata">

**Author:** ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)\
**Post date:** [February 26, 2020, 11:49pm UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/3 "2020-02-26T23:49:03Z")

</div>

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

```auto
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);
    
  }     
  }

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:01am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/4 "2020-02-27T00:01:25Z")

</div>

??

Didn’t you like my reply?

So why start a new thread…?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:02am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/5 "2020-02-27T00:02:28Z")

</div>

Just implement what I told you

---

<div class="post-metadata">

**Author:** ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)\
**Post date:** [February 27, 2020, 12:03am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/6 "2020-02-27T00:03:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:06am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/7 "2020-02-27T00:06:57Z")

</div>

At the beginning of mousePressed

set the boolean true

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:08am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/8 "2020-02-27T00:08:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:09am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/9 "2020-02-27T00:09:22Z")

</div>

Then use the timer to control your boolean showText

---

<div class="post-metadata">

**Author:** ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)\
**Post date:** [February 27, 2020, 12:09am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/10 "2020-02-27T00:09:57Z")

</div>

thank you!

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:12am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/11 "2020-02-27T00:12:48Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![NotConsumable](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@NotConsumable](https://discourse.processing.org/u/NotConsumable)\
**Post date:** [February 27, 2020, 12:14am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/12 "2020-02-27T00:14:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 12:23am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/13 "2020-02-27T00:23:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 8:22am UTC](https://discourse.processing.org/t/creating-a-frame-timer/18165/14 "2020-02-27T08:22:30Z")

</div>

Maybe you can post your result here in a nice way
