mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
examples/audio: Enable to touch
This commit is contained in:
parent
027463ff88
commit
311d53ce2e
@ -212,13 +212,26 @@ func (p *Player) switchPlayStateIfNeeded() {
|
||||
p.audioPlayer.Play()
|
||||
}
|
||||
|
||||
func (p *Player) seekBarIfNeeded() {
|
||||
if !inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
|
||||
return
|
||||
func justPressedPosition() (int, int, bool) {
|
||||
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
|
||||
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.
|
||||
x, y := ebiten.CursorPosition()
|
||||
x, y, ok := justPressedPosition()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
bx, by, bw, bh := playerBarRect()
|
||||
const padding = 4
|
||||
if y < by-padding || by+bh+padding <= y {
|
||||
|
Loading…
Reference in New Issue
Block a user