examples/wav: Play SE immediately

This commit is contained in:
Hajime Hoshi 2020-10-10 05:03:51 +09:00
parent b1c67c7661
commit 10f394f72b

View File

@ -25,6 +25,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/audio/wav" "github.com/hajimehoshi/ebiten/v2/audio/wav"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
raudio "github.com/hajimehoshi/ebiten/v2/examples/resources/audio" raudio "github.com/hajimehoshi/ebiten/v2/examples/resources/audio"
"github.com/hajimehoshi/ebiten/v2/inpututil"
) )
const ( const (
@ -73,7 +74,7 @@ func init() {
} }
func (g *Game) Update() error { func (g *Game) Update() error {
if ebiten.IsKeyPressed(ebiten.KeyP) && !g.audioPlayer.IsPlaying() { if inpututil.IsKeyJustPressed(ebiten.KeyP) {
// As audioPlayer has one stream and remembers the playing position, // As audioPlayer has one stream and remembers the playing position,
// rewinding is needed before playing when reusing audioPlayer. // rewinding is needed before playing when reusing audioPlayer.
g.audioPlayer.Rewind() g.audioPlayer.Rewind()