mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
parent
b6f7a0043c
commit
d14202ef7b
@ -170,6 +170,7 @@ type Context struct {
|
||||
players *players
|
||||
sampleRate int
|
||||
err error
|
||||
ready bool
|
||||
|
||||
m sync.Mutex
|
||||
}
|
||||
@ -266,15 +267,27 @@ func (c *Context) loop() {
|
||||
case <-suspendCh:
|
||||
<-resumeCh
|
||||
default:
|
||||
const n = 2048
|
||||
if _, err := io.CopyN(p, c.players, n); err != nil {
|
||||
if _, err := io.CopyN(p, c.players, 2048); err != nil {
|
||||
c.err = err
|
||||
return
|
||||
}
|
||||
c.m.Lock()
|
||||
c.ready = true
|
||||
c.m.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsReady returns a boolean value indicating whether the audio is ready or not.
|
||||
//
|
||||
// On some browsers, user interaction like click or pressing keys is required to start audio.
|
||||
func (c *Context) IsReady() bool {
|
||||
c.m.Lock()
|
||||
r := c.ready
|
||||
c.m.Unlock()
|
||||
return r
|
||||
}
|
||||
|
||||
// Update is deprecated as of 1.6.0-alpha.
|
||||
//
|
||||
// As of 1.6.0-alpha, Update always returns nil and does nothing related to updating the state.
|
||||
|
@ -139,7 +139,7 @@ var (
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
// Play notes for each half second.
|
||||
if frames%30 == 0 {
|
||||
if frames%30 == 0 && audioContext.IsReady() {
|
||||
currentNote = playNote(scoreIndex)
|
||||
scoreIndex++
|
||||
scoreIndex %= len(score)
|
||||
@ -151,11 +151,14 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
|
||||
msg := "Note: "
|
||||
if currentNote == 'R' {
|
||||
if currentNote == 'R' || currentNote == 0 {
|
||||
msg += "-"
|
||||
} else {
|
||||
msg += string(currentNote)
|
||||
}
|
||||
if !audioContext.IsReady() {
|
||||
msg += "\n\n(If the audio doesn't start,\n click the screen or press keys)"
|
||||
}
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
return nil
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/gopherjs/gopherwasm v1.0.0
|
||||
github.com/hajimehoshi/bitmapfont v1.1.1
|
||||
github.com/hajimehoshi/go-mp3 v0.1.1
|
||||
github.com/hajimehoshi/oto v0.2.0
|
||||
github.com/hajimehoshi/oto v0.2.1-0.20181013145203-3a9bb05c78a0
|
||||
github.com/jakecoffman/cp v0.1.0
|
||||
github.com/jfreymuth/oggvorbis v1.0.0
|
||||
github.com/jfreymuth/vorbis v1.0.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -24,6 +24,8 @@ github.com/hajimehoshi/oto v0.1.4 h1:YixDDnNhUjtrYP84YXISGWhQUN2VJfVIgKUeSNMWtxQ
|
||||
github.com/hajimehoshi/oto v0.1.4/go.mod h1:0ZepxT+2KLDrCm1gdkKBCQCxr+8fgQqoh0I7g+kr040=
|
||||
github.com/hajimehoshi/oto v0.2.0 h1:7JRO4/b+/xjWdV9ccUs35xcYTDrzRHxs5qnxeMHj7CM=
|
||||
github.com/hajimehoshi/oto v0.2.0/go.mod h1:0ZepxT+2KLDrCm1gdkKBCQCxr+8fgQqoh0I7g+kr040=
|
||||
github.com/hajimehoshi/oto v0.2.1-0.20181013145203-3a9bb05c78a0 h1:Ruf7x6Tkg6lx6fwHO8a38eR/cf+2GEX+9tAyJnqV8jc=
|
||||
github.com/hajimehoshi/oto v0.2.1-0.20181013145203-3a9bb05c78a0/go.mod h1:0ZepxT+2KLDrCm1gdkKBCQCxr+8fgQqoh0I7g+kr040=
|
||||
github.com/jakecoffman/cp v0.1.0 h1:sgSYEGUgfwiT447fRjloa2c5b6UyYP+7muR3gQK+Ep0=
|
||||
github.com/jakecoffman/cp v0.1.0/go.mod h1:a3xPx9N8RyFAACD644t2dj/nK4SuLg1v+jL61m2yVo4=
|
||||
github.com/jfreymuth/oggvorbis v1.0.0 h1:aOpiihGrFLXpsh2osOlEvTcg5/aluzGQeC7m3uYWOZ0=
|
||||
|
Loading…
Reference in New Issue
Block a user