mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +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
|
## 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)
|
* Input (Mouse, Keyboard, Gamepads, Touches)
|
||||||
* Audio (MP3, Ogg/Vorbis, WAV, PCM)
|
* Audio (MP3, Ogg/Vorbis, WAV, PCM)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<h2 id="features">Features</h2>
|
<h2 id="features">Features</h2>
|
||||||
<dl class="dl-horizontal">
|
<dl class="dl-horizontal">
|
||||||
<dt>2D Graphics</dt>
|
<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>
|
<dt>Input</dt>
|
||||||
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
|
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
|
||||||
<dt>Audio</dt>
|
<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
|
# 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
|
## jab.wav
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -17,13 +26,6 @@ http://mart.kitunebi.com/music_act.html
|
|||||||
Harpie's Feather (ハルピュイアの羽) by Napi
|
Harpie's Feather (ハルピュイアの羽) by Napi
|
||||||
```
|
```
|
||||||
|
|
||||||
## game2.mp3
|
|
||||||
|
|
||||||
```
|
|
||||||
http://mart.kitunebi.com/music_act.html
|
|
||||||
|
|
||||||
ノアの羽舟 by Napi
|
|
||||||
```
|
|
||||||
|
|
||||||
## ragtime.ogg
|
## ragtime.ogg
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/audio"
|
"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/audio/wav"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
)
|
)
|
||||||
@ -47,7 +47,7 @@ const (
|
|||||||
screenWidth = 320
|
screenWidth = 320
|
||||||
screenHeight = 240
|
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.
|
// but decoders adjust them.
|
||||||
sampleRate = 48000
|
sampleRate = 48000
|
||||||
)
|
)
|
||||||
@ -101,8 +101,8 @@ type Player struct {
|
|||||||
input *Input
|
input *Input
|
||||||
audioContext *audio.Context
|
audioContext *audio.Context
|
||||||
audioPlayer *audio.Player
|
audioPlayer *audio.Player
|
||||||
|
current time.Duration
|
||||||
total time.Duration
|
total time.Duration
|
||||||
seekedCh chan error
|
|
||||||
seBytes []uint8
|
seBytes []uint8
|
||||||
seCh chan []uint8
|
seCh chan []uint8
|
||||||
volume128 int
|
volume128 int
|
||||||
@ -126,11 +126,11 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
oggF, err := ebitenutil.OpenFile("_resources/audio/ragtime.ogg")
|
mp3F, err := ebitenutil.OpenFile("_resources/audio/classic.mp3")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s, err := vorbis.Decode(audioContext, oggF)
|
s, err := mp3.Decode(audioContext, mp3F)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -149,6 +149,9 @@ func NewPlayer(audioContext *audio.Context) (*Player, error) {
|
|||||||
volume128: 128,
|
volume128: 128,
|
||||||
seCh: make(chan []uint8),
|
seCh: make(chan []uint8),
|
||||||
}
|
}
|
||||||
|
if player.total == 0 {
|
||||||
|
player.total = 1
|
||||||
|
}
|
||||||
player.audioPlayer.Play()
|
player.audioPlayer.Play()
|
||||||
go func() {
|
go func() {
|
||||||
s, err := wav.Decode(audioContext, wavF)
|
s, err := wav.Decode(audioContext, wavF)
|
||||||
@ -172,14 +175,11 @@ func (p *Player) update() error {
|
|||||||
case p.seBytes = <-p.seCh:
|
case p.seBytes = <-p.seCh:
|
||||||
close(p.seCh)
|
close(p.seCh)
|
||||||
p.seCh = nil
|
p.seCh = nil
|
||||||
case err := <-p.seekedCh:
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
close(p.seekedCh)
|
|
||||||
p.seekedCh = nil
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
if p.audioPlayer.IsPlaying() {
|
||||||
|
p.current = p.audioPlayer.Current()
|
||||||
|
}
|
||||||
p.updateBar()
|
p.updateBar()
|
||||||
p.updatePlayPause()
|
p.updatePlayPause()
|
||||||
p.updateSE()
|
p.updateSE()
|
||||||
@ -229,9 +229,6 @@ func (p *Player) updatePlayPause() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) updateBar() {
|
func (p *Player) updateBar() {
|
||||||
if p.seekedCh != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !p.input.isMouseButtonTriggered(ebiten.MouseButtonLeft) {
|
if !p.input.isMouseButtonTriggered(ebiten.MouseButtonLeft) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -246,10 +243,8 @@ func (p *Player) updateBar() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
pos := time.Duration(x-bx) * p.total / time.Duration(bw)
|
pos := time.Duration(x-bx) * p.total / time.Duration(bw)
|
||||||
p.seekedCh = make(chan error, 1)
|
p.current = pos
|
||||||
go func() {
|
p.audioPlayer.Seek(pos)
|
||||||
p.seekedCh <- p.audioPlayer.Seek(pos)
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) close() error {
|
func (p *Player) close() error {
|
||||||
@ -262,11 +257,9 @@ func (p *Player) draw(screen *ebiten.Image) {
|
|||||||
op.GeoM.Translate(float64(x), float64(y))
|
op.GeoM.Translate(float64(x), float64(y))
|
||||||
screen.DrawImage(playerBarImage, op)
|
screen.DrawImage(playerBarImage, op)
|
||||||
currentTimeStr := "00:00"
|
currentTimeStr := "00:00"
|
||||||
c := p.audioPlayer.Current()
|
|
||||||
prev := p.previousPos
|
|
||||||
p.previousPos = c
|
|
||||||
|
|
||||||
// Current Time
|
// Current Time
|
||||||
|
c := p.current
|
||||||
m := (c / time.Minute) % 100
|
m := (c / time.Minute) % 100
|
||||||
s := (c / time.Second) % 60
|
s := (c / time.Second) % 60
|
||||||
currentTimeStr = fmt.Sprintf("%02d:%02d", m, s)
|
currentTimeStr = fmt.Sprintf("%02d:%02d", m, s)
|
||||||
@ -284,7 +277,10 @@ Press S to toggle Play/Pause
|
|||||||
Press P to play SE
|
Press P to play SE
|
||||||
Press Z or X to change volume of the music
|
Press Z or X to change volume of the music
|
||||||
%s`, ebiten.CurrentFPS(), currentTimeStr)
|
%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..."
|
msg += "\nLoading..."
|
||||||
}
|
}
|
||||||
ebitenutil.DebugPrint(screen, msg)
|
ebitenutil.DebugPrint(screen, msg)
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<h2 id="features">Features</h2>
|
<h2 id="features">Features</h2>
|
||||||
<dl class="dl-horizontal">
|
<dl class="dl-horizontal">
|
||||||
<dt>2D Graphics</dt>
|
<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>
|
<dt>Input</dt>
|
||||||
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
|
<dd>Mouse, Keyboard, Gamepads, Touches</dd>
|
||||||
<dt>Audio</dt>
|
<dt>Audio</dt>
|
||||||
|
Loading…
Reference in New Issue
Block a user