# How to change FrameRate

**URL:** <https://discourse.processing.org/t/how-to-change-framerate/38455>\
**Category:** Libraries\
**Created:** [August 22, 2022, 2:36pm UTC](https://discourse.processing.org/t/how-to-change-framerate/38455 "2022-08-22T14:36:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aladin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aladin/32/16650_2.png) [@aladin](https://discourse.processing.org/u/aladin)\
**Post date:** [August 22, 2022, 2:36pm UTC](https://discourse.processing.org/t/how-to-change-framerate/38455/1 "2022-08-22T14:36:51Z")

</div>

I am trying to set FrameRate using the framerate() function but it is not working, the actual framerate while running the code ranges between 1.8 - 4 fps , here is my setup code:

```auto
void setup (){
  System.out.println("displayHeight : "+displayHeight);
  System.out.println("displayWidth : "+displayWidth);
  setBG("white-frame.png");
  surface.setLocation(displayWidth/2-width/2, 0);
  surface.hideCursor() ;
  frameRate(frame_rate); // redraw 10 times in a second, refresh rate is 200 ms/frame
  //System.out.println("mapping sections List: "+Arrays.deepToString(pm.getMappingSections()));

  // Load the font
  f = createFont("font.ttf",150,true);
  textFont(f);

    file = new SoundFile(this, "Musica.mp3");
    file.play();
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [August 22, 2022, 2:53pm UTC](https://discourse.processing.org/t/how-to-change-framerate/38455/2 "2022-08-22T14:53:29Z")

</div>

Hi

Is this your code or part of it ?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 22, 2022, 3:04pm UTC](https://discourse.processing.org/t/how-to-change-framerate/38455/3 "2022-08-22T15:04:11Z")

</div>

> [@aladin](#):
>
> `redraw 10 times in a second, refresh rate is 200 ms/frame`

At 10 frames a second that allows a maximum of 100ms to render a frame??? If you expect the draw() method to take 200ms pef frame then the best frame rate you can get is ~5fps no matter what you put in `frameRate(?)`.

Difficult to say more about this because we can’t the value you store in `frame_rate` and we can’t see how much work you expect to do in the draw() method.

---

<div class="post-metadata">

**Author:** ![aladin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aladin/32/16650_2.png) [@aladin](https://discourse.processing.org/u/aladin)\
**Post date:** [August 26, 2022, 10:58am UTC](https://discourse.processing.org/t/how-to-change-framerate/38455/4 "2022-08-26T10:58:04Z")

</div>

this is only the setup part, I’ll post the entire code in the next comment

---

<div class="post-metadata">

**Author:** ![aladin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aladin/32/16650_2.png) [@aladin](https://discourse.processing.org/u/aladin)\
**Post date:** [August 26, 2022, 11:03am UTC](https://discourse.processing.org/t/how-to-change-framerate/38455/5 "2022-08-26T11:03:33Z")

</div>

> redraw 10 times in a second, refresh rate is 200 ms/frame  
> This is an old comment, the actual value of `frame_rate` is 100 but anyway, as I said before the execution frame rate is very low and is not affected by the value stored in `frame_rate` .  
> Regarding the other point, in the `draw()` function I draw images and shapes according to some values stored in a database table, the only heavy work here is the calls to the database server (in the testing process is the same machine).

```auto
void draw(){
  drawAlternater = !drawAlternater;
  setBG("white-frame.png");
  
  /// testing framerate
  textSize(100);
  textAlign(LEFT, TOP);
  text("FPS:" + frameRate, 0, 11);
  /// end of testing framerate
  
  if(introStep<maxIntroSteps) //introduction phase
  {
    intro(introStep);
    introStep++;
  }
  else if (downCounter > 0) // count down and show players' steps
  {
    finishedCountingScores = false;
    if(downCounter% frame_rate == 0)
    {
      textFont(f);
      textSize(100);
      fill(255);
      textAlign(LEFT);
      if(downCounter/frame_rate >=10)
      {
        text("00:"+downCounter/frame_rate, width/2 - textWidth("00:00")/2,displayHeight-50);
      }
      else
      {
        text("00:0"+downCounter/frame_rate, width/2 - textWidth("00:00")/2,displayHeight-50);
      }

    }

      Dictionary r = db.readPlayersTable();
      stroke(0);
      strokeWeight(GameConstants.stepStrokeWeight);
      rb.redraw((int)r.get("RED"));
      bb.redraw((int)r.get("BLUE"));
      gb.redraw((int)r.get("GREEN"));
      yb.redraw((int)r.get("YELLOW"));
      setFG("white-mask.png");

      // decrement counter
      if(downCounter > 0)downCounter--;
    }
    else if(!finishedCountingScores)
    {
      countScores(drawAlternater);

    }
    else
    {
      // show winner
      showWinner();
    }
  }

```
