mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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>
|
||||
<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
|
||||
|
||||
import (
|
||||
@ -71,7 +74,7 @@ type Input struct {
|
||||
}
|
||||
|
||||
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) {
|
||||
i.keyStates[key] = 0
|
||||
} else {
|
||||
@ -183,6 +186,10 @@ func (p *Player) update() error {
|
||||
p.updatePlayPause()
|
||||
p.updateSE()
|
||||
p.updateVolume()
|
||||
if p.input.isKeyTriggered(ebiten.KeyB) {
|
||||
b := ebiten.IsRunnableInBackground()
|
||||
ebiten.SetRunnableInBackground(!b)
|
||||
}
|
||||
if err := p.audioContext.Update(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -275,6 +282,7 @@ func (p *Player) draw(screen *ebiten.Image) {
|
||||
Press S to toggle Play/Pause
|
||||
Press P to play SE
|
||||
Press Z or X to change volume of the music
|
||||
Press B to switch the run-in-background state
|
||||
%s`, ebiten.CurrentFPS(), currentTimeStr)
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
}
|
||||
|
@ -165,8 +165,6 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
imageEmpty, _ := ebiten.NewImage(16, 16, ebiten.FilterNearest)
|
||||
imageEmpty.Fill(color.White)
|
||||
imagePiano, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
||||
whiteKeys := []string{"A", "S", "D", "F", "G", "H", "J", "K", "L"}
|
||||
width := 24
|
||||
@ -174,12 +172,7 @@ func init() {
|
||||
for i, k := range whiteKeys {
|
||||
x := i*width + 36
|
||||
height := 112
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
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)
|
||||
ebitenutil.DrawRect(imagePiano, float64(x), float64(y), float64(width-1), float64(height), color.White)
|
||||
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.Black)
|
||||
}
|
||||
|
||||
@ -190,12 +183,7 @@ func init() {
|
||||
}
|
||||
x := i*width + 24
|
||||
height := 64
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
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)
|
||||
ebitenutil.DrawRect(imagePiano, float64(x), float64(y), float64(width-1), float64(height), color.Black)
|
||||
common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.White)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user