Loading...
Logo
Processing Forum

frameRate

in Programming Questions  •  4 months ago  
Hello, the default frame rate is 60. How can i make a higher frame rate? when is set it to 100 or 1000 i see no difference to 60. I need a higher frame rate. How can i solve this?

Replies(6)

Re: frameRate

4 months ago
To set the frame rate to 100 fps use
  frameRate(100);

This method is like a speed limiter in that it caps the frame rate. Ultimately the maximum frame rate is dependent on your computer system.

Re: frameRate

3 months ago
Ok, i see no difference.

I will try to explain you my problem. I want to make a little jump'n run game. A character is running from left to right and has to jump over a obstacle. To increase the speed i do x=x+0.7*displayWidth. But it looks not very good. A second probelm (see the picture):
1,2,3 are the positions of the character , the higher the speed the less the positions i have.
That means, when someone will click between 2 and 3 (before the obstacle) my character will die.

Thats my main problem. I need more frames per second.

Here a beta:

I hope i was able to explain my problem.

Re: frameRate

3 months ago
The answer I gave answered your question which was
I need a higher frame rate. How can i solve this?
The following sketch proves it - try changing fps 60/100/1000 and see what I mean

Copy code
  1. int fps = 100;

  2. public void setup(){
  3.   size(300,300);
  4.   background(255);
  5.   fill(0);
  6.   frameRate(fps);
  7. }

  8. public void draw(){
  9.   if(frameCount % fps == 0){
  10.     background(255);
  11.     text(""+ frameRate , 20, 40);
  12.   }
  13. }

Altering the frame rate to speed up your animation is not a good idea, will not always work and assumes that the users computer can achieve that speed.

 The best solution is to measure the time between each frame and use this to control your animation. This gives you an animation that is not dependent on the frame rate. In the following code the ball will take the same time to reach the right-hand-side of the display no matter what frame rate the computer can achieve - try changing fps.

Copy code
  1. int fps = 100;
  2. int ltime, ctime;
  3. float etime;
  4. float velocity = 10; // 10 pixels per second
  5. float x = 30; // start position

  6. public void setup() {
  7.   size(300, 300);
  8.   background(255);
  9.   fill(0);
  10.   frameRate(fps);
  11.   ltime = ctime = millis();
  12. }

  13. public void draw() {
  14.   // Calculate the elapsed time (etime) in seconds
  15.   ctime = millis();
  16.   etime = (ctime - ltime)/1000.0;
  17.   ltime = ctime;
  18.   background(255);
  19.   x = x + velocity * etime;
  20.   ellipse(x, 50, 6, 6);
  21. }



Re: Re: frameRate

3 months ago
Thank you very much! That's it!

How can i fit this to different screen sizes?

It will be an android app.

Re: frameRate

3 months ago

How can i fit this to different screen sizes?

It will be an android app.
I don't know - I suggest you ask the question in the Android Processing forum.

Re: frameRate

3 months ago
maybe u could make the mesures in % like: (displayWidth/100) * the % ?