mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +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()
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user