Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to get the elapsed time between frames #6070

Open
clankill3r opened this issue Jul 17, 2020 · 2 comments · May be fixed by #6106
Open

add method to get the elapsed time between frames #6070

clankill3r opened this issue Jul 17, 2020 · 2 comments · May be fixed by #6106

Comments

@clankill3r
Copy link

I think it would be a great addition to have a deltaTime added to processing so it is more easy to make frame independent movement out of the box.

I know you can do something like:

float speed = 100;
x += speed / frameRate;

But it is more common in computer graphics to make use of a deltaTime.
Here is an example sketch:

float last_frame_time;
float current_frame_time;
float delta_time;


float speed = 100;
float x = 0;

float x2;

void setup() {
  size(600, 600);
  frameRate(999999); // <<< TEST WITH CHANGING THIS!
}

void draw() {

  last_frame_time = current_frame_time;
  current_frame_time = millis();
  delta_time = (current_frame_time - last_frame_time) / 1000;
  
  background(0);
  fill(255,255,0);
  
  x += speed * delta_time;
  ellipse(x, 300, 20, 20);
  
  if (x > width + 10) x = 0;
  
  println(frameRate);
  
  x2 += speed / frameRate;
  ellipse(x2, 350, 20, 20);
  if (x2 > width + 10) x2 = 0;
  
}

Maybe this adds to much to processing, I don't know. But I thought let's open it up for discussion.

@jeremydouglass
Copy link
Contributor

Interesting idea. What might it be called? The current two main sources of time are:

  • millis()
  • frameCount

Your example defines deltaTime by dividing millis by 1000, but I'm assuming that a raw value named deltaMillis() or frameMillis() would be more useful...?

@benfry benfry changed the title add a deltaTime to processing add elapsed time between frames to processing Sep 23, 2020
@benfry benfry changed the title add elapsed time between frames to processing add method to get the elapsed time between frames Sep 23, 2020
@botelho-io
Copy link

Working on deltaMillis(), I always wanted a function like this!

@botelho-io botelho-io linked a pull request Oct 9, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants