mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +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"
|
"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.
|
// Run runs the game.
|
||||||
// f is a function which is called at every frame.
|
// 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()
|
now := time.Now().UnixNano()
|
||||||
frames++
|
frames++
|
||||||
if time.Second <= time.Duration(now-t) {
|
if time.Second <= time.Duration(now-t) {
|
||||||
fps = int(int64(frames) * int64(time.Second) / (now - t))
|
fps = float64(frames) * float64(time.Second) / float64(now-t)
|
||||||
// TODO: How to show the current FPS?
|
|
||||||
t = now
|
t = now
|
||||||
frames = 0
|
frames = 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user