ui: Add fps, tps display
This commit is contained in:
@@ -2,8 +2,10 @@ package ui
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/inpututil"
|
||||
)
|
||||
|
||||
@@ -20,6 +22,8 @@ type Window struct {
|
||||
// User-provided update actions
|
||||
updateFn func() error
|
||||
drawFn func(*ebiten.Image) error
|
||||
|
||||
debug bool
|
||||
}
|
||||
|
||||
// 0,0 is the *top left* of the window
|
||||
@@ -31,6 +35,7 @@ func NewWindow(title string) (*Window, error) {
|
||||
return &Window{
|
||||
Title: title,
|
||||
KeyUpHandlers: make(map[ebiten.Key]func()),
|
||||
debug: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -68,6 +73,12 @@ func (w *Window) run(screen *ebiten.Image) error {
|
||||
if err := w.drawFn(screen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if w.debug {
|
||||
// Draw FPS, etc, to the screen
|
||||
msg := fmt.Sprintf("tps=%0.2f fps=%0.2f", ebiten.CurrentTPS(), ebiten.CurrentFPS())
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user