# Can someone Help me with a Timer

**URL:** <https://discourse.processing.org/t/can-someone-help-me-with-a-timer/30240>\
**Category:** Processing for Android\
**Created:** [May 23, 2021, 7:43pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-a-timer/30240 "2021-05-23T19:43:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)\
**Post date:** [May 23, 2021, 7:43pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-a-timer/30240/1 "2021-05-23T19:43:49Z")

</div>

I visit a timer during the game when side is on 1 for 10 seconds afterwards side should be set to 2

```auto
import processing.sound.*;
boolean startp = true;
float c;
int seite, score, rx, ry;
SoundFile theme;
SoundFile plus;
SoundFile win;

void setup() {
  colorMode(HSB);
  seite = 0;
  score = 0;
  fullScreen();
  frameRate(60);
  textAlign(CENTER);
  theme = new SoundFile(this, "theme.mp3");
  plus = new SoundFile(this, "plus.mp3");
  win = new SoundFile(this, "Wini.mp3");
  theme.loop();
}

void draw () {
  if(seite==0){
    background(#292929);
    if (c >= 255) c=0; else c++;
    fill(c, 255, 255);
    textSize(55*displayDensity);
    text("Follow the Rect", width/2, height/3.8);
    fill(#545454);
    rect(width/4, height/2.5, width/2, height/12);
    fill(#FFFFFF);
    textSize(40*displayDensity);
    text("Play", width/2, height/2.2);
    if(mousePressed = mouseX > width/4 && mouseX < width/4 + width/2 && mouseY > height/2.5 && mouseY < height/2.5 + height/12){
      delay(300);
      theme.stop();
      mouseX = width/2;
      mouseY = height/2;
      seite=1;
      }
  }
  if (seite==1) {
    background(#292929);
    textSize(50*displayDensity);
    text("Score: "+score, width/2, height/12);
    rectMode(CORNER);
    fill(#535353);
    rect(width/8, height/4.5, width/1.3, height/1.4, 7*displayDensity);
    stroke(#00DCFF);
    strokeWeight(12.0);
    strokeCap(ROUND);
    rectMode(CENTER);
    line(mouseX, mouseY, rx, ry);
    strokeWeight(0);
    stroke(#FFFFFF);
    if (startp == false) {
      fill(#A80000);
      rect(rx, ry, width/15, height/30);
    } else {
      rx = int(random(width/7.98, width/1.28));
      ry = int(random(height/4.48, height/1.38));
      startp = false;
    }
    if (dist(mouseX, mouseY, rx, ry)<=width/15+height/30) {
      plus.play();
      score++;
      startp = true;
    }
    if(score>=10){
      startp = true;
      seite = 2;
      delay(50);
      win.play();
    }
  }
  if(seite==2){
    background(#292929);
    text("Gewonnen", width/2, height/2);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)\
**Post date:** [May 24, 2021, 1:23pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-a-timer/30240/2 "2021-05-24T13:23:07Z")

</div>

You can Create a time like that:

> **Click here to see the code**
>
> ```auto
> float currentTime = 0;
> 
> float timeToNextSeite = 10;//in sekunden
> 
> int seite = 0;
> 
> void setup() {
> size(800, 800);
> }
> void draw() {
> switch(seite) {
> case 0:
> showSeite1();
> break;
> case 1:
> showSeite2();
> break;
> case 2:
> showSeite3();
> break;
> }
> }
> void showSeite1() {
> background(255, 0, 0);
> fill(0);
> textSize(40);
> //str(int) makes the int to a string
> textAlign(CENTER, CENTER);
> text(str(round(currentTime)), 0, 0, width, height);
> currentTime += 1 / frameRate;
> if (currentTime >= timeToNextSeite) {
> //10 Seconds are over
> seite++;//seite = seite + 1; in short
> 
> currentTime -= timeToNextSeite;
> }
> }
> void showSeite2() {
> background(0, 255, 0);
> fill(0);
> textSize(40);
> //str(int) makes the int to a string
> textAlign(CENTER, CENTER);
> text(str(round(currentTime)), 0, 0, width, height);
> currentTime += 1 / frameRate;
> if (currentTime >= timeToNextSeite) {
> //10 Seconds are over
> seite++;//seite = seite + 1; in short
> 
> currentTime -= timeToNextSeite;
> }
> }
> void showSeite3() {
> background(0, 0, 255);
> fill(0);
> textSize(40);
> //str(int) makes the int to a string
> textAlign(CENTER, CENTER);
> text(str(round(currentTime)), 0, 0, width, height);
> currentTime += 1 / frameRate;
> if (currentTime >= timeToNextSeite) {
> //10 Seconds are over
> seite = 0;//seite = seite + 1; in short
> 
> currentTime -= timeToNextSeite;
> }
> }
> 
> ```

And I would recommend you to use an Enum:

> **Click here to see the code**
>
> ```auto
> //Create an Enum "class"
> enum SCENE {
> //Here are the Types from the enum 
> START, 
> GAME, 
> WIN, 
> LOSE, 
> LOAD
> //ect.
> }
> //Create a variable
> SCENE currentScene = SCENE.START;
> void example(){
> //now you can set the scene
> currentScene = SCENE.START;
> //or
> currentScene = SCENE.GAME;
> //ect
> }
> 
> ```

I hope I could help you  
Flolo 🙂
