examples/audio: Enable to touch

This commit is contained in:
Hajime Hoshi 2021-02-21 19:20:24 +09:00
parent 027463ff88
commit 311d53ce2e

View File

@ -212,13 +212,26 @@ func (p *Player) switchPlayStateIfNeeded() {
p.audioPlayer.Play() p.audioPlayer.Play()
} }
func (p *Player) seekBarIfNeeded() { func justPressedPosition() (int, int, bool) {
if !inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) { if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
return x, y := ebiten.CursorPosition()
return x, y, true
} }
if ts := inpututil.JustPressedTouchIDs(); len(ts) > 0 {
x, y := ebiten.TouchPosition(ts[0])
return x, y, true
}
return 0, 0, false
}
func (p *Player) seekBarIfNeeded() {
// Calculate the next seeking position from the current cursor position. // Calculate the next seeking position from the current cursor position.
x, y := ebiten.CursorPosition() x, y, ok := justPressedPosition()
if !ok {
return
}
bx, by, bw, bh := playerBarRect() bx, by, bw, bh := playerBarRect()
const padding = 4 const padding = 4
if y < by-padding || by+bh+padding <= y { if y < by-padding || by+bh+padding <= y {