Ebitenのメモ | TheoryOfContraints official blog

Ebitenのメモ

Go言語でゲームのプログラムが作れるebitenで画面表示の部分を作ったのでメモ

 

// copy
var (
    subImg    *ebiten.Image
    op      *ebiten.DrawImageOptions
)

func GrapCopyGet(fromScreen *ebiten.Image, x, y int, mx, my int) {
    subImg = fromScreen.SubImage(image.Rect(x, y, mx, my)).(*ebiten.Image)
    op = &ebiten.DrawImageOptions{}
}

func GrapCopyScale(dx, dy float64, angle float64) {
    w, h := subImg.Size()
    var wx, wy float64 = float64(w) * dx, float64(h) * dy

    op.GeoM.Scale(dx, dy)
    op.GeoM.Translate(-wx/2, -wy/2)
    op.GeoM.Rotate(angle / 180 * math.Pi)
    op.GeoM.Translate(wx/2, wy/2)
}

func GrapCopyAlpha(alpha float64) {
    op.ColorM.Scale(1, 1, 1, alpha)
}

func GrapCopyDraw(x,y float64) {
    op.GeoM.Translate(x, y)
    screenImage.DrawImage(subImg, op)
}