Use screen scaling

This commit is contained in:
2020-03-19 18:44:51 +00:00
parent 276885298a
commit d50a160f02

View File

@@ -13,8 +13,7 @@ import (
)
var (
winX = flag.Int("win-x", 1280, "width of the view-map window")
winY = flag.Int("win-y", 1024, "height of the view-map window")
screenScale = flag.Float64("screen-scale", 1.0, "Scale the window by this factor")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
)
@@ -29,6 +28,7 @@ type Window struct {
drawFn func(*ebiten.Image) error
debug bool
firstRun bool
}
// 0,0 is the *top left* of the window
@@ -41,6 +41,7 @@ func NewWindow(title string) (*Window, error) {
Title: title,
KeyUpHandlers: make(map[ebiten.Key]func()),
debug: true,
firstRun: true,
}, nil
}
@@ -54,6 +55,11 @@ func (w *Window) OnMouseWheel(f func(x, y float64)) {
}
func (w *Window) run(screen *ebiten.Image) error {
if w.firstRun {
ebiten.SetScreenScale(*screenScale)
w.firstRun = false
}
if err := w.updateFn(); err != nil {
return err
}
@@ -108,5 +114,5 @@ func (w *Window) Run(updateFn func() error, drawFn func(*ebiten.Image) error) er
defer pprof.StopCPUProfile()
}
return ebiten.Run(w.run, *winX, *winY, 1, w.Title)
return ebiten.Run(w.run, 640, 480, 1, w.Title) // Native game resolution: 640x480
}