Skip to content

Commit

Permalink
Merge pull request #54 from SaltieRL/pa-time
Browse files Browse the repository at this point in the history
Return elapsed time based on current frame
  • Loading branch information
Abbondanzo committed Aug 15, 2019
2 parents 3964425 + 5e58cd6 commit 151fb76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/eventbus/events/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import EventBus from "../EventBus"
*/
export interface FrameEvent {
frame: number
elapsedTime: number
}

export const {
Expand Down
12 changes: 11 additions & 1 deletion src/utils/FPSClock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export default class FPSClock {
return delta / 1000
}

/**
* Returns the elapsed time in milliseconds.
*/
public getElapsedTime() {
return this.frameToDuration[this.currentFrame]
}

private update() {
if (!this.paused) {
this.getElapsedFrames()
Expand Down Expand Up @@ -139,7 +146,10 @@ export default class FPSClock {
}

private doCallbacks() {
dispatchFrameEvent({ frame: this.currentFrame })
dispatchFrameEvent({
frame: this.currentFrame,
elapsedTime: this.getElapsedTime(),
})
}

/**
Expand Down

0 comments on commit 151fb76

Please sign in to comment.