mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
doc: Update
This commit is contained in:
parent
e596271002
commit
6f4f4ed06f
@ -18,7 +18,7 @@ Note: Gamepad is not available on Safari/Android/iOS. Keyboard is not available
|
||||
|
||||
## Features
|
||||
|
||||
* 2D Graphics (Geometry/Color matrix transformation, Various composition modes, Offscreen rendering)
|
||||
* 2D Graphics (Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen)
|
||||
* Input (Mouse, Keyboard, Gamepads, Touches)
|
||||
* Audio (MP3, Ogg/Vorbis, WAV, PCM)
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
<h2 id="features">Features</h2>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>2D Graphics</dt>
|
||||
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering</dd>
|
||||
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen</dd>
|
||||
<dt>Input</dt>
|
||||
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
|
||||
<dt>Audio</dt>
|
||||
|
BIN
docs/examples/_resources/audio/classic.mp3
Normal file
BIN
docs/examples/_resources/audio/classic.mp3
Normal file
Binary file not shown.
@ -1,5 +1,14 @@
|
||||
# License
|
||||
|
||||
## classic.mp3
|
||||
|
||||
```
|
||||
https://musopen.org/music/466/johann-sebastian-bach/air-on-the-g-string-from-orchestral-suite-no-3-bwv-1068/
|
||||
|
||||
Air on the G String (from Orchestral Suite no. 3, BWV 1068)
|
||||
Public Domain
|
||||
```
|
||||
|
||||
## jab.wav
|
||||
|
||||
```
|
||||
@ -17,13 +26,6 @@ http://mart.kitunebi.com/music_act.html
|
||||
Harpie's Feather (ハルピュイアの羽) by Napi
|
||||
```
|
||||
|
||||
## game2.mp3
|
||||
|
||||
```
|
||||
http://mart.kitunebi.com/music_act.html
|
||||
|
||||
ノアの羽舟 by Napi
|
||||
```
|
||||
|
||||
## ragtime.ogg
|
||||
|
||||
|
@ -38,7 +38,7 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/audio"
|
||||
"github.com/hajimehoshi/ebiten/audio/vorbis"
|
||||
"github.com/hajimehoshi/ebiten/audio/mp3"
|
||||
"github.com/hajimehoshi/ebiten/audio/wav"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
)
|
||||
@ -47,7 +47,7 @@ const (
|
||||
screenWidth = 320
|
||||
screenHeight = 240
|
||||
|
||||
// This sample rate doesn't match with wav/ogg's sample rate,
|
||||
// This sample rate doesn't match with wav/mp3's sample rate,
|
||||
// but decoders adjust them.
|
||||
sampleRate = 48000
|
||||
)
|
||||
@ -101,8 +101,8 @@ type Player struct {
|
||||
input *Input
|
||||
audioContext *audio.Context
|
||||
audioPlayer *audio.Player
|
||||
current time.Duration
|
||||
total time.Duration
|
||||
seekedCh chan error
|
||||
seBytes []uint8
|
||||
seCh chan []uint8
|
||||
volume128 int
|
||||
@ -126,11 +126,11 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oggF, err := ebitenutil.OpenFile("_resources/audio/ragtime.ogg")
|
||||
mp3F, err := ebitenutil.OpenFile("_resources/audio/classic.mp3")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s, err := vorbis.Decode(audioContext, oggF)
|
||||
s, err := mp3.Decode(audioContext, mp3F)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -149,6 +149,9 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) {
|
||||
volume128: 128,
|
||||
seCh: make(chan []uint8),
|
||||
}
|
||||
if player.total == 0 {
|
||||
player.total = 1
|
||||
}
|
||||
player.audioPlayer.Play()
|
||||
go func() {
|
||||
s, err := wav.Decode(audioContext, wavF)
|
||||
@ -172,14 +175,11 @@ func (p *Player) update() error {
|
||||
case p.seBytes = <-p.seCh:
|
||||
close(p.seCh)
|
||||
p.seCh = nil
|
||||
case err := <-p.seekedCh:
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
close(p.seekedCh)
|
||||
p.seekedCh = nil
|
||||
default:
|
||||
}
|
||||
if p.audioPlayer.IsPlaying() {
|
||||
p.current = p.audioPlayer.Current()
|
||||
}
|
||||
p.updateBar()
|
||||
p.updatePlayPause()
|
||||
p.updateSE()
|
||||
@ -229,9 +229,6 @@ func (p *Player) updatePlayPause() {
|
||||
}
|
||||
|
||||
func (p *Player) updateBar() {
|
||||
if p.seekedCh != nil {
|
||||
return
|
||||
}
|
||||
if !p.input.isMouseButtonTriggered(ebiten.MouseButtonLeft) {
|
||||
return
|
||||
}
|
||||
@ -246,10 +243,8 @@ func (p *Player) updateBar() {
|
||||
return
|
||||
}
|
||||
pos := time.Duration(x-bx) * p.total / time.Duration(bw)
|
||||
p.seekedCh = make(chan error, 1)
|
||||
go func() {
|
||||
p.seekedCh <- p.audioPlayer.Seek(pos)
|
||||
}()
|
||||
p.current = pos
|
||||
p.audioPlayer.Seek(pos)
|
||||
}
|
||||
|
||||
func (p *Player) close() error {
|
||||
@ -262,11 +257,9 @@ func (p *Player) draw(screen *ebiten.Image) {
|
||||
op.GeoM.Translate(float64(x), float64(y))
|
||||
screen.DrawImage(playerBarImage, op)
|
||||
currentTimeStr := "00:00"
|
||||
c := p.audioPlayer.Current()
|
||||
prev := p.previousPos
|
||||
p.previousPos = c
|
||||
|
||||
// Current Time
|
||||
c := p.current
|
||||
m := (c / time.Minute) % 100
|
||||
s := (c / time.Second) % 60
|
||||
currentTimeStr = fmt.Sprintf("%02d:%02d", m, s)
|
||||
@ -284,7 +277,10 @@ Press S to toggle Play/Pause
|
||||
Press P to play SE
|
||||
Press Z or X to change volume of the music
|
||||
%s`, ebiten.CurrentFPS(), currentTimeStr)
|
||||
if p.audioPlayer.IsPlaying() && prev == c {
|
||||
current := p.audioPlayer.Current()
|
||||
prev := p.previousPos
|
||||
p.previousPos = p.audioPlayer.Current()
|
||||
if p.audioPlayer.IsPlaying() && prev == current {
|
||||
msg += "\nLoading..."
|
||||
}
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
|
@ -47,7 +47,7 @@
|
||||
<h2 id="features">Features</h2>
|
||||
<dl class="dl-horizontal">
|
||||
<dt>2D Graphics</dt>
|
||||
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering</dd>
|
||||
<dd>Geometry/Color matrix transformation, Various composition modes, Offscreen rendering, Fullscreen</dd>
|
||||
<dt>Input</dt>
|
||||
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
|
||||
<dt>Audio</dt>
|
||||
|
Loading…
Reference in New Issue
Block a user