better scaling

This change uses a scaled window size with a fix logical screen size
in order to let Ebitengine do a better scaling.

Updates #24
Updates hajimehoshi/ebiten#2951
This commit is contained in:
Hajime Hoshi
2024-04-06 15:11:24 +09:00
parent eb5fed9b4f
commit 3538f6fd3c

17
main.go
View File

@@ -42,6 +42,11 @@ type Config struct {
Quiet bool `ini:"quiet" cfg:"quiet" cfgDefault:"false" cfgHelper:"Disable sound."`
}
const (
width = 32
height = 32
)
var (
mSprite map[string]*ebiten.Image
mSound map[string][]byte
@@ -49,9 +54,6 @@ var (
//go:embed assets/*
f embed.FS
width = 32
height = 32
monitorWidth, monitorHeight = ebiten.ScreenSizeInFullscreen()
cfg = &Config{}
@@ -232,9 +234,7 @@ func (m *neko) Draw(screen *ebiten.Image) {
screen.Clear()
op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(cfg.Scale, cfg.Scale)
screen.DrawImage(m.img, op)
screen.DrawImage(m.img, nil)
}
func main() {
@@ -242,9 +242,6 @@ func main() {
config.File = "neko.ini"
config.Parse(cfg)
width = int(float64(width) * cfg.Scale)
height = int(float64(height) * cfg.Scale)
mSprite = make(map[string]*ebiten.Image)
mSound = make(map[string][]byte)
@@ -296,7 +293,7 @@ func main() {
ebiten.SetVsyncEnabled(true)
ebiten.SetWindowDecorated(false)
ebiten.SetWindowFloating(true)
ebiten.SetWindowSize(width, height)
ebiten.SetWindowSize(int(float64(width)*cfg.Scale), int(float64(height)*cfg.Scale))
ebiten.SetWindowTitle("Neko")
err := ebiten.RunGameWithOptions(n, &ebiten.RunGameOptions{