examples: Bug fix: updating audio context should sync with updating logic

This commit is contained in:
Hajime Hoshi 2017-06-03 01:46:03 +09:00
parent 7bb917d4f6
commit 91b5d985fe
3 changed files with 9 additions and 10 deletions

View File

@ -182,6 +182,9 @@ func update(screen *ebiten.Image) error {
musicPlayer.updateSE() musicPlayer.updateSE()
musicPlayer.updateVolume() musicPlayer.updateVolume()
} }
if err := audioContext.Update(); err != nil {
return err
}
if ebiten.IsRunningSlowly() { if ebiten.IsRunningSlowly() {
return nil return nil
} }
@ -227,9 +230,6 @@ Press Z or X to change volume of the music
} }
} }
ebitenutil.DebugPrint(screen, msg) ebitenutil.DebugPrint(screen, msg)
if err := audioContext.Update(); err != nil {
return err
}
return nil return nil
} }

View File

@ -195,6 +195,9 @@ func update(screen *ebiten.Image) error {
} }
addNote(220*math.Exp2(float64(i-1)/12.0), 1.0) addNote(220*math.Exp2(float64(i-1)/12.0), 1.0)
} }
if err := audioContext.Update(); err != nil {
return err
}
if ebiten.IsRunningSlowly() { if ebiten.IsRunningSlowly() {
return nil return nil
} }
@ -202,10 +205,6 @@ func update(screen *ebiten.Image) error {
screen.DrawImage(imagePiano, nil) screen.DrawImage(imagePiano, nil)
ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())) ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
if err := audioContext.Update(); err != nil {
return err
}
return nil return nil
} }

View File

@ -97,14 +97,14 @@ func update(screen *ebiten.Image) error {
} }
player.Play() player.Play()
} }
if err := audioContext.Update(); err != nil {
return err
}
if ebiten.IsRunningSlowly() { if ebiten.IsRunningSlowly() {
return nil return nil
} }
msg := fmt.Sprintf("FPS: %0.2f\nThis is an example using infinite audio stream.", ebiten.CurrentFPS()) msg := fmt.Sprintf("FPS: %0.2f\nThis is an example using infinite audio stream.", ebiten.CurrentFPS())
ebitenutil.DebugPrint(screen, msg) ebitenutil.DebugPrint(screen, msg)
if err := audioContext.Update(); err != nil {
return err
}
return nil return nil
} }