examples/blocks: Use ebitenutil.DrawRect

This commit is contained in:
Hajime Hoshi 2017-08-14 00:33:00 +09:00
parent 0fc28f6e98
commit f08d21866a

View File

@ -29,7 +29,6 @@ import (
) )
var ( var (
imageEmpty *ebiten.Image
imageGameBG *ebiten.Image imageGameBG *ebiten.Image
imageWindows *ebiten.Image imageWindows *ebiten.Image
imageGameover *ebiten.Image imageGameover *ebiten.Image
@ -70,10 +69,6 @@ func linesTextBoxPosition() (x, y int) {
} }
func init() { func init() {
// Empty
imageEmpty, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
imageEmpty.Fill(color.White)
// Background // Background
var err error var err error
imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterLinear) imageGameBG, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterLinear)
@ -109,12 +104,7 @@ func init() {
} }
func drawWindow(r *ebiten.Image, x, y, width, height int) { func drawWindow(r *ebiten.Image, x, y, width, height int) {
op := &ebiten.DrawImageOptions{} ebitenutil.DrawRect(r, float64(x), float64(y), float64(width), float64(height), color.RGBA{0, 0, 0, 0xc0})
w, h := imageEmpty.Size()
op.GeoM.Scale(float64(width)/float64(w), float64(height)/float64(h))
op.GeoM.Translate(float64(x), float64(y))
op.ColorM.Scale(0, 0, 0, 0.75)
r.DrawImage(imageEmpty, op)
} }
var fontColor = color.NRGBA{0x40, 0x40, 0xff, 0xff} var fontColor = color.NRGBA{0x40, 0x40, 0xff, 0xff}