diff --git a/graphicscontext.go b/graphicscontext.go index 2aff1c724..7aebec8fb 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -22,6 +22,7 @@ import ( "github.com/hajimehoshi/ebiten/internal/driver" "github.com/hajimehoshi/ebiten/internal/graphicscommand" "github.com/hajimehoshi/ebiten/internal/hooks" + "github.com/hajimehoshi/ebiten/internal/input" "github.com/hajimehoshi/ebiten/internal/shareable" "github.com/hajimehoshi/ebiten/internal/ui" ) @@ -114,6 +115,8 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error { if err := c.f(c.offscreen); err != nil { return err } + + input.Get().ResetForFrame() afterFrameUpdate() } diff --git a/internal/input/input_glfw.go b/internal/input/input_glfw.go index 84c21c900..ee878916b 100644 --- a/internal/input/input_glfw.go +++ b/internal/input/input_glfw.go @@ -47,7 +47,7 @@ func (i *Input) RuneBuffer() []rune { return i.runeBuffer } -func (i *Input) Reset() { +func (i *Input) ResetForFrame() { i.m.RLock() defer i.m.RUnlock() i.runeBuffer = i.runeBuffer[:0] diff --git a/internal/input/input_js.go b/internal/input/input_js.go index b20c1c9b0..1cb623c6f 100644 --- a/internal/input/input_js.go +++ b/internal/input/input_js.go @@ -49,7 +49,7 @@ func (i *Input) RuneBuffer() []rune { return i.runeBuffer } -func (i *Input) Reset() { +func (i *Input) ResetForFrame() { i.runeBuffer = nil i.wheelX = 0 i.wheelY = 0 diff --git a/internal/input/input_mobile.go b/internal/input/input_mobile.go index b1e7f35dc..eea6edb68 100644 --- a/internal/input/input_mobile.go +++ b/internal/input/input_mobile.go @@ -57,3 +57,7 @@ func (i *Input) SetTouches(touches []*Touch) { } i.m.Unlock() } + +func (i *Input) ResetForFrame() { + // Do nothing +} diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 40e10e3b8..39ba60d35 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -780,7 +780,6 @@ func (u *userInterface) update(g GraphicsContext) error { return nil }) if err := g.Update(func() { - input.Get().Reset() // The offscreens must be updated every frame (#490). u.updateGraphicsContext(g) }); err != nil { diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index de9149218..018ffdcfb 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -206,7 +206,6 @@ func (u *userInterface) update(g GraphicsContext) error { input.Get().UpdateGamepads() u.updateGraphicsContext(g) if err := g.Update(func() { - input.Get().Reset() u.updateGraphicsContext(g) }); err != nil { return err