examples: audioContext.Update should be called at last

This commit is contained in:
Hajime Hoshi 2016-04-22 01:11:28 +09:00
parent 3c3d275e5e
commit 62243f97b5
4 changed files with 13 additions and 12 deletions

View File

@ -181,9 +181,6 @@ func (p *Player) close() error {
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if err := audioContext.Update(); err != nil {
return err
}
if musicPlayer == nil { if musicPlayer == nil {
select { select {
case musicPlayer = <-musicCh: case musicPlayer = <-musicCh:
@ -242,6 +239,9 @@ Press Z or X to change volume of the music
msg += "\nNow Loading..." msg += "\nNow Loading..."
} }
ebitenutil.DebugPrint(screen, msg) ebitenutil.DebugPrint(screen, msg)
if err := audioContext.Update(); err != nil {
return err
}
return nil return nil
} }

View File

@ -145,9 +145,6 @@ func addNote() error {
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if err := audioContext.Update(); err != nil {
return err
}
defer func() { defer func() {
frames++ frames++
}() }()
@ -157,6 +154,9 @@ func update(screen *ebiten.Image) error {
} }
} }
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

@ -206,9 +206,6 @@ func init() {
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if err := audioContext.Update(); err != nil {
return err
}
updateInput() updateInput()
for i, key := range keys { for i, key := range keys {
if keyStates[key] != 1 { if keyStates[key] != 1 {
@ -223,6 +220,10 @@ 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

@ -87,9 +87,6 @@ func (s *stream) Close() error {
var player *audio.Player var player *audio.Player
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if err := audioContext.Update(); err != nil {
return err
}
if player == nil { if player == nil {
var err error var err error
player, err = audio.NewPlayer(audioContext, &stream{}) player, err = audio.NewPlayer(audioContext, &stream{})
@ -101,6 +98,9 @@ func update(screen *ebiten.Image) error {
} }
} }
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
} }