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
- int fps = 100;
- public void setup(){
- size(300,300);
- background(255);
- fill(0);
- frameRate(fps);
- }
- public void draw(){
- if(frameCount % fps == 0){
- background(255);
- text(""+ frameRate , 20, 40);
- }
- }
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.
- int fps = 100;
- int ltime, ctime;
- float etime;
- float velocity = 10; // 10 pixels per second
- float x = 30; // start position
- public void setup() {
- size(300, 300);
- background(255);
- fill(0);
- frameRate(fps);
- ltime = ctime = millis();
- }
- public void draw() {
- // Calculate the elapsed time (etime) in seconds
- ctime = millis();
- etime = (ctime - ltime)/1000.0;
- ltime = ctime;
- background(255);
- x = x + velocity * etime;
- ellipse(x, 50, 6, 6);
- }