UNTESTED: ebiten v2

This commit is contained in:
2020-11-21 19:27:09 +00:00
parent c5e6abb798
commit 92fa0fc5d6
22 changed files with 92 additions and 132 deletions

View File

@@ -1,7 +1,7 @@
package ui
import (
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
)
var (

View File

@@ -5,8 +5,8 @@ import (
"image"
"runtime/debug"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"code.ur.gs/lupine/ordoor/internal/assetstore"
)
@@ -137,9 +137,7 @@ func (d *Driver) Draw(screen *ebiten.Image) error {
do.GeoM = d.orig2native
do.GeoM.Translate(x, y)
if err := screen.DrawImage(region.image, &do); err != nil {
return err
}
screen.DrawImage(region.image, &do)
}
}

View File

@@ -3,7 +3,7 @@ package ui
import (
"image"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/v2"
)
type region struct {

View File

@@ -8,9 +8,9 @@ import (
"runtime/debug"
"runtime/pprof"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/inpututil"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Game interface {
@@ -53,8 +53,6 @@ type Window struct {
//
// ebiten assumes a single window, so only call this once...
func NewWindow(game Game, title string, xRes int, yRes int) (*Window, error) {
ebiten.SetRunnableInBackground(true)
return &Window{
Title: title,
debug: true,
@@ -109,10 +107,12 @@ func (w *Window) drawCursor(screen *ebiten.Image) error {
ebiten.SetCursorMode(ebiten.CursorModeHidden)
return screen.DrawImage(cursor, op)
screen.DrawImage(cursor, op)
return nil
}
func (w *Window) Update(screen *ebiten.Image) (outErr error) {
func (w *Window) Update() (outErr error) {
// Ebiten does not like it if we panic inside its main loop
defer func() {
if panicErr := recover(); panicErr != nil {
@@ -124,7 +124,8 @@ func (w *Window) Update(screen *ebiten.Image) (outErr error) {
}
}()
if err := w.game.Update(screen.Size()); err != nil {
// FIXME: remove need for update generally
if err := w.game.Update(w.xRes, w.yRes); err != nil {
return err
}
@@ -157,13 +158,11 @@ func (w *Window) Update(screen *ebiten.Image) (outErr error) {
}
}
if ebiten.IsDrawingSkipped() {
return nil
}
return nil
}
if err := w.game.Draw(screen); err != nil {
return err
}
func (w *Window) Draw(screen *ebiten.Image) {
w.game.Draw(screen)
if w.debug {
// Draw FPS, etc, to the screen
@@ -172,7 +171,7 @@ func (w *Window) Update(screen *ebiten.Image) (outErr error) {
}
// Draw the cursor last
return w.drawCursor(screen)
w.drawCursor(screen)
}
// TODO: a stop or other cancellation mechanism