mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/ui: bug fix: input states must be updated before the hook
Closes #2502
This commit is contained in:
parent
8ccfa7bec1
commit
d3655940bd
@ -147,9 +147,11 @@ func (g *gameForUI) Layout(outsideWidth, outsideHeight float64) (float64, float6
|
||||
return float64(sw), float64(sh)
|
||||
}
|
||||
|
||||
func (g *gameForUI) Update(inputState ui.InputState) error {
|
||||
func (g *gameForUI) UpdateInputState(inputState ui.InputState) {
|
||||
theInputState.set(inputState)
|
||||
}
|
||||
|
||||
func (g *gameForUI) Update() error {
|
||||
if err := g.game.Update(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ type Game interface {
|
||||
NewOffscreenImage(width, height int) *Image
|
||||
NewScreenImage(width, height int) *Image
|
||||
Layout(outsideWidth, outsideHeight float64) (screenWidth, screenHeight float64)
|
||||
Update(InputState) error
|
||||
UpdateInputState(InputState)
|
||||
Update() error
|
||||
DrawOffscreen() error
|
||||
DrawFinalScreen(scale, offsetX, offsetY float64)
|
||||
}
|
||||
@ -123,14 +124,15 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
||||
|
||||
// Update the game.
|
||||
for i := 0; i < updateCount; i++ {
|
||||
if err := hooks.RunBeforeUpdateHooks(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read the input state and use it for one tick to give a consistent result for one tick (#2496, #2501).
|
||||
var inputState InputState
|
||||
ui.readInputState(&inputState)
|
||||
if err := c.game.Update(inputState); err != nil {
|
||||
c.game.UpdateInputState(inputState)
|
||||
|
||||
if err := hooks.RunBeforeUpdateHooks(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.game.Update(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user