mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
doc: Update examples
This commit is contained in:
parent
a225f666ac
commit
179b3134e3
@ -27,6 +27,9 @@
|
|||||||
<iframe src="audio.content.html" width="640" height="480"></iframe>
|
<iframe src="audio.content.html" width="640" height="480"></iframe>
|
||||||
<pre><code class="language-go">// +build example
|
<pre><code class="language-go">// +build example
|
||||||
|
|
||||||
|
// This is an example to implement an audio player.
|
||||||
|
// See examples/wav for a simpler example to play a sound file.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -71,7 +74,7 @@ type Input struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *Input) update() {
|
func (i *Input) update() {
|
||||||
for _, key := range []ebiten.Key{ebiten.KeyP, ebiten.KeyS, ebiten.KeyX, ebiten.KeyZ} {
|
for _, key := range []ebiten.Key{ebiten.KeyP, ebiten.KeyS, ebiten.KeyX, ebiten.KeyZ, ebiten.KeyB} {
|
||||||
if !ebiten.IsKeyPressed(key) {
|
if !ebiten.IsKeyPressed(key) {
|
||||||
i.keyStates[key] = 0
|
i.keyStates[key] = 0
|
||||||
} else {
|
} else {
|
||||||
@ -183,6 +186,10 @@ func (p *Player) update() error {
|
|||||||
p.updatePlayPause()
|
p.updatePlayPause()
|
||||||
p.updateSE()
|
p.updateSE()
|
||||||
p.updateVolume()
|
p.updateVolume()
|
||||||
|
if p.input.isKeyTriggered(ebiten.KeyB) {
|
||||||
|
b := ebiten.IsRunnableInBackground()
|
||||||
|
ebiten.SetRunnableInBackground(!b)
|
||||||
|
}
|
||||||
if err := p.audioContext.Update(); err != nil {
|
if err := p.audioContext.Update(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -275,6 +282,7 @@ func (p *Player) draw(screen *ebiten.Image) {
|
|||||||
Press S to toggle Play/Pause
|
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
|
||||||
|
Press B to switch the run-in-background state
|
||||||
%s`, ebiten.CurrentFPS(), currentTimeStr)
|
%s`, ebiten.CurrentFPS(), currentTimeStr)
|
||||||
ebitenutil.DebugPrint(screen, msg)
|
ebitenutil.DebugPrint(screen, msg)
|
||||||
}
|
}
|
||||||
|
@ -165,8 +165,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
imageEmpty, _ := ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
|
||||||
imageEmpty.Fill(color.White)
|
|
||||||
imagePiano, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
imagePiano, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
||||||
whiteKeys := []string{"A", "S", "D", "F", "G", "H", "J", "K", "L"}
|
whiteKeys := []string{"A", "S", "D", "F", "G", "H", "J", "K", "L"}
|
||||||
width := 24
|
width := 24
|
||||||
@ -174,12 +172,7 @@ func init() {
|
|||||||
for i, k := range whiteKeys {
|
for i, k := range whiteKeys {
|
||||||
x := i*width + 36
|
x := i*width + 36
|
||||||
height := 112
|
height := 112
|
||||||
op := &ebiten.DrawImageOptions{}
|
ebitenutil.DrawRect(imagePiano, float64(x), float64(y), float64(width-1), float64(height), color.White)
|
||||||
w, h := imageEmpty.Size()
|
|
||||||
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
|
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
|
||||||
op.ColorM.Scale(1, 1, 1, 1)
|
|
||||||
imagePiano.DrawImage(imageEmpty, op)
|
|
||||||
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.Black)
|
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.Black)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,12 +183,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
x := i*width + 24
|
x := i*width + 24
|
||||||
height := 64
|
height := 64
|
||||||
op := &ebiten.DrawImageOptions{}
|
ebitenutil.DrawRect(imagePiano, float64(x), float64(y), float64(width-1), float64(height), color.Black)
|
||||||
w, h := imageEmpty.Size()
|
|
||||||
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
|
|
||||||
op.GeoM.Translate(float64(x), float64(y))
|
|
||||||
op.ColorM.Scale(0, 0, 0, 1)
|
|
||||||
imagePiano.DrawImage(imageEmpty, op)
|
|
||||||
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.White)
|
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.White)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user