docs: Update example pages

This commit is contained in:
Hajime Hoshi 2017-03-04 23:27:25 +09:00
parent ef8da64680
commit db9c5d00ce
17 changed files with 74 additions and 211 deletions

View File

@ -79,17 +79,13 @@ func update(screen *ebiten.Image) error {
diff = float64(480-count) * 0.2 diff = float64(480-count) * 0.2
} }
if err := screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff}); err != nil { screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
return err
}
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5) op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
op.ImageParts = &imageParts{ op.ImageParts = &imageParts{
diff: diff, diff: diff,
} }
if err := screen.DrawImage(ebitenImage, op); err != nil { screen.DrawImage(ebitenImage, op)
return err
}
return nil return nil
} }

View File

@ -115,9 +115,9 @@ func (p *Player) updateSE() error {
return sePlayer.Play() return sePlayer.Play()
} }
func (p *Player) updateVolume() error { func (p *Player) updateVolume() {
if p.audioPlayer == nil { if p.audioPlayer == nil {
return nil return
} }
if ebiten.IsKeyPressed(ebiten.KeyZ) { if ebiten.IsKeyPressed(ebiten.KeyZ) {
volume128-- volume128--
@ -132,7 +132,6 @@ func (p *Player) updateVolume() error {
volume128 = 128 volume128 = 128
} }
p.audioPlayer.SetVolume(float64(volume128) / 128) p.audioPlayer.SetVolume(float64(volume128) / 128)
return nil
} }
func (p *Player) updatePlayPause() error { func (p *Player) updatePlayPause() error {
@ -153,29 +152,29 @@ func (p *Player) updatePlayPause() error {
return p.audioPlayer.Play() return p.audioPlayer.Play()
} }
func (p *Player) updateBar() error { func (p *Player) updateBar() {
if p.audioPlayer == nil { if p.audioPlayer == nil {
return nil return
} }
if p.seekedCh != nil { if p.seekedCh != nil {
return nil return
} }
if !ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { if !ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
mouseButtonState[ebiten.MouseButtonLeft] = 0 mouseButtonState[ebiten.MouseButtonLeft] = 0
return nil return
} }
mouseButtonState[ebiten.MouseButtonLeft]++ mouseButtonState[ebiten.MouseButtonLeft]++
if mouseButtonState[ebiten.MouseButtonLeft] != 1 { if mouseButtonState[ebiten.MouseButtonLeft] != 1 {
return nil return
} }
x, y := ebiten.CursorPosition() x, y := ebiten.CursorPosition()
bx, by, bw, bh := playerBarRect() bx, by, bw, bh := playerBarRect()
const padding = 4 const padding = 4
if y < by-padding || by+bh+padding <= y { if y < by-padding || by+bh+padding <= y {
return nil return
} }
if x < bx || bx+bw <= x { if x < bx || bx+bw <= x {
return nil 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.seekedCh = make(chan error, 1)
@ -183,7 +182,6 @@ func (p *Player) updateBar() error {
// This can't be done parallely! !?!? // This can't be done parallely! !?!?
p.seekedCh <- p.audioPlayer.Seek(pos) p.seekedCh <- p.audioPlayer.Seek(pos)
}() }()
return nil
} }
func (p *Player) close() error { func (p *Player) close() error {
@ -204,26 +202,20 @@ func update(screen *ebiten.Image) error {
} }
} }
if musicPlayer != nil { if musicPlayer != nil {
if err := musicPlayer.updateBar(); err != nil { musicPlayer.updateBar()
return err
}
if err := musicPlayer.updatePlayPause(); err != nil { if err := musicPlayer.updatePlayPause(); err != nil {
return err return err
} }
if err := musicPlayer.updateSE(); err != nil { if err := musicPlayer.updateSE(); err != nil {
return err return err
} }
if err := musicPlayer.updateVolume(); err != nil { musicPlayer.updateVolume()
return err
}
} }
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
x, y, w, h := playerBarRect() x, y, w, h := playerBarRect()
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))
if err := screen.DrawImage(playerBarImage, op); err != nil { screen.DrawImage(playerBarImage, op)
return err
}
currentTimeStr := "00:00" currentTimeStr := "00:00"
if musicPlayer != nil { if musicPlayer != nil {
c := musicPlayer.audioPlayer.Current() c := musicPlayer.audioPlayer.Current()
@ -239,9 +231,7 @@ func update(screen *ebiten.Image) error {
cy := y - (ch-h)/2 cy := y - (ch-h)/2
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(cx), float64(cy)) op.GeoM.Translate(float64(cx), float64(cy))
if err := screen.DrawImage(playerCurrentImage, op); err != nil { screen.DrawImage(playerCurrentImage, op)
return err
}
} }
msg := fmt.Sprintf(`FPS: %0.2f msg := fmt.Sprintf(`FPS: %0.2f
@ -263,9 +253,7 @@ Press Z or X to change volume of the music
msg += "\nSeeking..." msg += "\nSeeking..."
} }
} }
if err := ebitenutil.DebugPrint(screen, msg); err != nil { ebitenutil.DebugPrint(screen, msg)
return err
}
if err := audioContext.Update(); err != nil { if err := audioContext.Update(); err != nil {
return err return err
} }

View File

@ -97,22 +97,17 @@ func parseFont() error {
d.DrawString(s) d.DrawString(s)
y += size y += size
} }
return textImage.ReplacePixels(dst.Pix) textImage.ReplacePixels(dst.Pix)
return nil
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
if err := screen.DrawImage(textImage, &ebiten.DrawImageOptions{}); err != nil { screen.DrawImage(textImage, &ebiten.DrawImageOptions{})
return err
}
return nil return nil
} }
func main() { func main() {
var err error textImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
textImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := parseFont(); err != nil { if err := parseFont(); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -69,9 +69,7 @@ func update(screen *ebiten.Image) error {
Pressed Buttons: {{.Buttons}}` Pressed Buttons: {{.Buttons}}`
str = strings.Replace(str, "{{.Axes}}", strings.Join(axes, "\n "), -1) str = strings.Replace(str, "{{.Axes}}", strings.Join(axes, "\n "), -1)
str = strings.Replace(str, "{{.Buttons}}", strings.Join(pressedButtons, ", "), -1) str = strings.Replace(str, "{{.Buttons}}", strings.Join(pressedButtons, ", "), -1)
if err := ebitenutil.DebugPrint(screen, str); err != nil { ebitenutil.DebugPrint(screen, str)
return err
}
return nil return nil
} }

View File

@ -94,16 +94,12 @@ func update(screen *ebiten.Image) error {
saturation := float64(saturationInt) / 128 saturation := float64(saturationInt) / 128
value := float64(valueInt) / 128 value := float64(valueInt) / 128
op.ColorM.ChangeHSV(hue, saturation, value) op.ColorM.ChangeHSV(hue, saturation, value)
if err := screen.DrawImage(gophersImage, op); err != nil { screen.DrawImage(gophersImage, op)
return err
}
msg := fmt.Sprintf(`Hue: %0.2f [Q][W] msg := fmt.Sprintf(`Hue: %0.2f [Q][W]
Saturation: %0.2f [A][S] Saturation: %0.2f [A][S]
Value: %0.2f [Z][X]`, hue, saturation, value) Value: %0.2f [Z][X]`, hue, saturation, value)
if err := ebitenutil.DebugPrint(screen, msg); err != nil { ebitenutil.DebugPrint(screen, msg)
return err
}
return nil return nil
} }

View File

@ -54,9 +54,7 @@ func update(screen *ebiten.Image) error {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2) op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
op.ColorM.RotateHue(float64(count%360) * 2 * math.Pi / 360) op.ColorM.RotateHue(float64(count%360) * 2 * math.Pi / 360)
if err := screen.DrawImage(gophersImage, op); err != nil { screen.DrawImage(gophersImage, op)
return err
}
return nil return nil
} }

View File

@ -86,41 +86,27 @@ func (p *viewport) Position() (int, int) {
return p.x16, p.y16 return p.x16, p.y16
} }
func updateGroundImage(ground *ebiten.Image) error { func updateGroundImage(ground *ebiten.Image) {
if err := ground.Clear(); err != nil { ground.Clear()
return err
}
x16, y16 := theViewport.Position() x16, y16 := theViewport.Position()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16) op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16)
if err := ground.DrawImage(repeatedBgImage, op); err != nil { ground.DrawImage(repeatedBgImage, op)
return err
}
return nil
} }
func drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) error { func drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
if err := screen.DrawImage(ground, op); err != nil { screen.DrawImage(ground, op)
return err
}
return nil
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
theViewport.Move() theViewport.Move()
if err := updateGroundImage(groundImage); err != nil { updateGroundImage(groundImage)
return err drawGroundImage(screen, groundImage)
}
if err := drawGroundImage(screen, groundImage); err != nil {
return err
}
msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()) msg := fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())
if err := ebitenutil.DebugPrint(screen, msg); err != nil { ebitenutil.DebugPrint(screen, msg)
return err
}
return nil return nil
} }
@ -132,23 +118,15 @@ func main() {
} }
w, h := bgImage.Size() w, h := bgImage.Size()
const repeat = 5 const repeat = 5
repeatedBgImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest) repeatedBgImage, _ = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
for j := 0; j < repeat; j++ { for j := 0; j < repeat; j++ {
for i := 0; i < repeat; i++ { for i := 0; i < repeat; i++ {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(w*i), float64(h*j)) op.GeoM.Translate(float64(w*i), float64(h*j))
if err := repeatedBgImage.DrawImage(bgImage, op); err != nil { repeatedBgImage.DrawImage(bgImage, op)
log.Fatal(err)
}
} }
} }
groundImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) groundImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "infinite scroll"); err != nil { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "infinite scroll"); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -99,9 +99,7 @@ func update(screen *ebiten.Image) error {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(offsetX, offsetY) op.GeoM.Translate(offsetX, offsetY)
op.ColorM.Scale(0.5, 0.5, 0.5, 1) op.ColorM.Scale(0.5, 0.5, 0.5, 1)
if err := screen.DrawImage(keyboardImage, op); err != nil { screen.DrawImage(keyboardImage, op)
return err
}
pressed := []string{} pressed := []string{}
for i := 0; i <= 9; i++ { for i := 0; i <= 9; i++ {
@ -129,9 +127,7 @@ func update(screen *ebiten.Image) error {
ImageParts: pressedKeysParts(pressed), ImageParts: pressedKeysParts(pressed),
} }
op.GeoM.Translate(offsetX, offsetY) op.GeoM.Translate(offsetX, offsetY)
if err := screen.DrawImage(keyboardImage, op); err != nil { screen.DrawImage(keyboardImage, op)
return err
}
return nil return nil
} }

View File

@ -185,9 +185,7 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
world.Progress() world.Progress()
world.DrawImage(noiseImage) world.DrawImage(noiseImage)
if err := screen.ReplacePixels(noiseImage.Pix); err != nil { screen.ReplacePixels(noiseImage.Pix)
return err
}
return nil return nil
} }

View File

@ -78,31 +78,19 @@ func update(screen *ebiten.Image) error {
spotLightVY = -spotLightVY spotLightVY = -spotLightVY
} }
if err := maskImage.Clear(); err != nil { maskImage.Clear()
return err
}
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(spotLightX), float64(spotLightY)) op.GeoM.Translate(float64(spotLightX), float64(spotLightY))
if err := maskImage.DrawImage(spotLightImage, op); err != nil { maskImage.DrawImage(spotLightImage, op)
return err
}
op = &ebiten.DrawImageOptions{} op = &ebiten.DrawImageOptions{}
op.CompositeMode = ebiten.CompositeModeSourceOut op.CompositeMode = ebiten.CompositeModeSourceOut
if err := maskImage.DrawImage(fiveyearsImage, op); err != nil { maskImage.DrawImage(fiveyearsImage, op)
return err
}
if err := screen.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff}); err != nil { screen.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff})
return err screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{})
} screen.DrawImage(maskImage, &ebiten.DrawImageOptions{})
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{}); err != nil {
return err
}
if err := screen.DrawImage(maskImage, &ebiten.DrawImageOptions{}); err != nil {
return err
}
return nil return nil
} }
@ -131,10 +119,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
maskImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) maskImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
as := image.Point{128, 128} as := image.Point{128, 128}
a := image.NewAlpha(image.Rectangle{image.ZP, as}) a := image.NewAlpha(image.Rectangle{image.ZP, as})
@ -146,10 +131,7 @@ func main() {
a.SetAlpha(i, j, color.Alpha{b}) a.SetAlpha(i, j, color.Alpha{b})
} }
} }
spotLightImage, err = ebiten.NewImageFromImage(a, ebiten.FilterNearest) spotLightImage, _ = ebiten.NewImageFromImage(a, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Masking (Ebiten Demo)"); err != nil { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Masking (Ebiten Demo)"); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -52,14 +52,10 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio) op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
if err := gophersRenderTarget.DrawImage(gophersImage, op); err != nil { gophersRenderTarget.DrawImage(gophersImage, op)
return err
}
op = &ebiten.DrawImageOptions{} op = &ebiten.DrawImageOptions{}
op.GeoM.Scale(mosaicRatio, mosaicRatio) op.GeoM.Scale(mosaicRatio, mosaicRatio)
if err := screen.DrawImage(gophersRenderTarget, op); err != nil { screen.DrawImage(gophersRenderTarget, op)
return err
}
return nil return nil
} }
@ -70,10 +66,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
w, h := gophersImage.Size() w, h := gophersImage.Size()
gophersRenderTarget, err = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest) gophersRenderTarget, _ = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -71,12 +71,8 @@ func update(screen *ebiten.Image) error {
noiseImage.Pix[4*i+2] = uint8(x >> 8) noiseImage.Pix[4*i+2] = uint8(x >> 8)
noiseImage.Pix[4*i+3] = 0xff noiseImage.Pix[4*i+3] = 0xff
} }
if err := screen.ReplacePixels(noiseImage.Pix); err != nil { screen.ReplacePixels(noiseImage.Pix)
return err ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS()))
}
if err := ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %f", ebiten.CurrentFPS())); err != nil {
return err
}
return nil return nil
} }

View File

@ -51,55 +51,43 @@ var (
canvasImage *ebiten.Image canvasImage *ebiten.Image
) )
func paint(screen *ebiten.Image, x, y int) error { func paint(screen *ebiten.Image, x, y int) {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(1.0, 0.50, 0.125, 1.0) op.ColorM.Scale(1.0, 0.50, 0.125, 1.0)
theta := 2.0 * math.Pi * float64(count%60) / ebiten.FPS theta := 2.0 * math.Pi * float64(count%60) / ebiten.FPS
op.ColorM.RotateHue(theta) op.ColorM.RotateHue(theta)
if err := canvasImage.DrawImage(brushImage, op); err != nil { canvasImage.DrawImage(brushImage, op)
return err
}
return nil
} }
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
drawn := false drawn := false
mx, my := ebiten.CursorPosition() mx, my := ebiten.CursorPosition()
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
if err := paint(screen, mx, my); err != nil { paint(screen, mx, my)
return err
}
drawn = true drawn = true
} }
for _, t := range ebiten.Touches() { for _, t := range ebiten.Touches() {
x, y := t.Position() x, y := t.Position()
if err := paint(screen, x, y); err != nil { paint(screen, x, y)
return err
}
drawn = true drawn = true
} }
if drawn { if drawn {
count++ count++
} }
if err := screen.DrawImage(canvasImage, nil); err != nil { screen.DrawImage(canvasImage, nil)
return err
}
msg := fmt.Sprintf("(%d, %d)", mx, my) msg := fmt.Sprintf("(%d, %d)", mx, my)
for _, t := range ebiten.Touches() { for _, t := range ebiten.Touches() {
x, y := t.Position() x, y := t.Position()
msg += fmt.Sprintf("\n(%d, %d) touch %d", x, y, t.ID()) msg += fmt.Sprintf("\n(%d, %d) touch %d", x, y, t.ID())
} }
if err := ebitenutil.DebugPrint(screen, msg); err != nil { ebitenutil.DebugPrint(screen, msg)
return err
}
return nil return nil
} }
func main() { func main() {
var err error
const a0, a1, a2 = 0x40, 0xc0, 0xff const a0, a1, a2 = 0x40, 0xc0, 0xff
pixels := []uint8{ pixels := []uint8{
a0, a1, a1, a0, a0, a1, a1, a0,
@ -107,22 +95,14 @@ func main() {
a1, a2, a2, a1, a1, a2, a2, a1,
a0, a1, a1, a0, a0, a1, a1, a0,
} }
brushImage, err = ebiten.NewImageFromImage(&image.Alpha{ brushImage, _ = ebiten.NewImageFromImage(&image.Alpha{
Pix: pixels, Pix: pixels,
Stride: 4, Stride: 4,
Rect: image.Rect(0, 0, 4, 4), Rect: image.Rect(0, 0, 4, 4),
}, ebiten.FilterNearest) }, ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
canvasImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) canvasImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil { canvasImage.Fill(color.White)
log.Fatal(err)
}
if err := canvasImage.Fill(color.White); err != nil {
log.Fatal(err)
}
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Paint (Ebiten Demo)"); err != nil { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Paint (Ebiten Demo)"); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -75,9 +75,7 @@ func update(screen *ebiten.Image) error {
maxWidth := float64(w) + float64(h)*0.75 maxWidth := float64(w) + float64(h)*0.75
op.GeoM.Translate(-maxWidth/2, -float64(h)/2) op.GeoM.Translate(-maxWidth/2, -float64(h)/2)
op.GeoM.Translate(screenWidth/2, screenHeight/2) op.GeoM.Translate(screenWidth/2, screenHeight/2)
if err := screen.DrawImage(gophersImage, op); err != nil { screen.DrawImage(gophersImage, op)
return err
}
return nil return nil
} }

View File

@ -175,18 +175,9 @@ var (
) )
func init() { func init() {
var err error imageEmpty, _ := ebiten.NewImage(16, 16, ebiten.FilterNearest)
imageEmpty, err := ebiten.NewImage(16, 16, ebiten.FilterNearest) imageEmpty.Fill(color.White)
if err != nil { imagePiano, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
panic(err)
}
if err := imageEmpty.Fill(color.White); err != nil {
panic(err)
}
imagePiano, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
if err != nil {
panic(err)
}
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
y := 48 y := 48
@ -198,12 +189,8 @@ func init() {
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h)) op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(1, 1, 1, 1) op.ColorM.Scale(1, 1, 1, 1)
if err := imagePiano.DrawImage(imageEmpty, op); err != nil { imagePiano.DrawImage(imageEmpty, op)
panic(err) common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.Black)
}
if err := common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.Black); err != nil {
panic(err)
}
} }
blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"} blackKeys := []string{"Q", "W", "", "R", "T", "", "U", "I", "O"}
@ -218,12 +205,8 @@ func init() {
op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h)) op.GeoM.Scale(float64(width-1)/float64(w), float64(height)/float64(h))
op.GeoM.Translate(float64(x), float64(y)) op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(0, 0, 0, 1) op.ColorM.Scale(0, 0, 0, 1)
if err := imagePiano.DrawImage(imageEmpty, op); err != nil { imagePiano.DrawImage(imageEmpty, op)
panic(err) common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.White)
}
if err := common.ArcadeFont.DrawText(imagePiano, k, x+8, y+height-16, 1, color.White); err != nil {
panic(err)
}
} }
} }
@ -238,16 +221,10 @@ func update(screen *ebiten.Image) error {
} }
} }
if err := screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff}); err != nil { screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
return err screen.DrawImage(imagePiano, nil)
}
if err := screen.DrawImage(imagePiano, nil); err != nil {
return err
}
if err := ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS())); err != nil { ebitenutil.DebugPrint(screen, fmt.Sprintf("FPS: %0.2f", ebiten.CurrentFPS()))
return err
}
if err := audioContext.Update(); err != nil { if err := audioContext.Update(); err != nil {
return err return err

View File

@ -55,9 +55,7 @@ func update(screen *ebiten.Image) error {
op.GeoM.Translate(-float64(w)/2, -float64(h)/2) op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360) op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360)
op.GeoM.Translate(screenWidth/2, screenHeight/2) op.GeoM.Translate(screenWidth/2, screenHeight/2)
if err := screen.DrawImage(gophersImage, op); err != nil { screen.DrawImage(gophersImage, op)
return err
}
return nil return nil
} }

View File

@ -137,15 +137,11 @@ func update(screen *ebiten.Image) error {
ImageParts: sprites, ImageParts: sprites,
} }
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5) op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
if err := screen.DrawImage(ebitenImage, op); err != nil { screen.DrawImage(ebitenImage, op)
return err
}
msg := fmt.Sprintf(`FPS: %0.2f msg := fmt.Sprintf(`FPS: %0.2f
Num of sprites: %d Num of sprites: %d
Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len()) Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.Len())
if err := ebitenutil.DebugPrint(screen, msg); err != nil { ebitenutil.DebugPrint(screen, msg)
return err
}
return nil return nil
} }