Jerome-Saltmarsh / dart-lemon-engine

A simple canvas and game loop
Other
49 stars 2 forks source link

delta time #6

Closed Dan-Crane closed 1 year ago

Dan-Crane commented 1 year ago

Can you please tell me how do I get the time difference from the past frame?

Dan-Crane commented 1 year ago

engine.durationPerUpdate has a stream that I can subscribe to and listen to the changes.

engine.durationPerUpdate.stream.listen((event) {
    time.updateDt(event.inMicroseconds / Duration.microsecondsPerSecond);
});
Jerome-Saltmarsh commented 1 year ago

You can use the msUpdate value, but that's a good point, I will integrate it into the update function itself as a paremeter

Jerome-Saltmarsh commented 1 year ago

durationPerUpdate is what what it aims for and msUpdate is the actual duration since the last frame.

Dan-Crane commented 1 year ago

That would be cool:)

Dan-Crane commented 1 year ago

I would like to have delta time in both onUpdate and onRender

Jerome-Saltmarsh commented 1 year ago

I added it to the onUpdate function (see 0.5.1)

the delta is a double which represents the goal_duration / actual_duration so any physics equations can use that decimal to maintain consistence

Jerome-Saltmarsh commented 1 year ago

the renderFunction is a little trickier because it can depend on the settings, if the drawCanvasAfterUpdate flag is true it will render after that, otherwise it might be rendered manually,

In any case you can still get the duration since the last render with the msRender variable.