mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
Add CurrentFPS
This commit is contained in:
parent
0332b8d5ed
commit
9d5ab644a4
10
run.go
10
run.go
@ -20,7 +20,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var fps = 0
|
||||
var fps = 0.0
|
||||
|
||||
// CurrentFPS returns the current number of frames per second.
|
||||
func CurrentFPS() float64 {
|
||||
return fps
|
||||
}
|
||||
|
||||
// Run runs the game.
|
||||
// f is a function which is called at every frame.
|
||||
@ -77,8 +82,7 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
|
||||
now := time.Now().UnixNano()
|
||||
frames++
|
||||
if time.Second <= time.Duration(now-t) {
|
||||
fps = int(int64(frames) * int64(time.Second) / (now - t))
|
||||
// TODO: How to show the current FPS?
|
||||
fps = float64(frames) * float64(time.Second) / float64(now-t)
|
||||
t = now
|
||||
frames = 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user