mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
examples/audioinfiniteloop: Refactoring: Remove magic numbers
This commit is contained in:
parent
56d8ce9935
commit
d243957ab1
@ -32,6 +32,9 @@ const (
|
|||||||
screenWidth = 320
|
screenWidth = 320
|
||||||
screenHeight = 240
|
screenHeight = 240
|
||||||
sampleRate = 44100
|
sampleRate = 44100
|
||||||
|
|
||||||
|
introLengthInSecond = 5
|
||||||
|
loopLengthInSecond = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
var audioContext *audio.Context
|
var audioContext *audio.Context
|
||||||
@ -57,7 +60,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
|
|
||||||
// Create an infinite loop stream from the decoded bytes.
|
// Create an infinite loop stream from the decoded bytes.
|
||||||
// s is still an io.ReadCloser and io.Seeker.
|
// s is still an io.ReadCloser and io.Seeker.
|
||||||
s := audio.NewInfiniteLoopWithIntro(oggS, 5*4*sampleRate, 4*4*sampleRate)
|
s := audio.NewInfiniteLoopWithIntro(oggS, introLengthInSecond*4*sampleRate, loopLengthInSecond*4*sampleRate)
|
||||||
|
|
||||||
player, err = audio.NewPlayer(audioContext, s)
|
player, err = audio.NewPlayer(audioContext, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,9 +81,9 @@ func update(screen *ebiten.Image) error {
|
|||||||
}
|
}
|
||||||
msg := fmt.Sprintf(`FPS: %0.2f
|
msg := fmt.Sprintf(`FPS: %0.2f
|
||||||
This is an example using audio.NewInfiniteLoop.
|
This is an example using audio.NewInfiniteLoop.
|
||||||
Intro: 0[s] - 5[s]
|
Intro: 0[s] - %[2]d[s]
|
||||||
Loop: 5[s] - 9[s]
|
Loop: %[2]d[s] - %[3]d[s]
|
||||||
Current: %0.2f[s]`, ebiten.CurrentFPS(), float64(pos)/float64(time.Second))
|
Current: %0.2[4]f[s]`, ebiten.CurrentFPS(), introLengthInSecond, introLengthInSecond+loopLengthInSecond, float64(pos)/float64(time.Second))
|
||||||
ebitenutil.DebugPrint(screen, msg)
|
ebitenutil.DebugPrint(screen, msg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user