examples: Rename texture -> image

This commit is contained in:
Hajime Hoshi 2014-12-21 03:05:36 +09:00
parent d774c19581
commit d34c94aa09
12 changed files with 106 additions and 106 deletions

View File

@ -32,7 +32,7 @@ const (
type Game struct { type Game struct {
count int count int
tmpRenderTarget *ebiten.RenderTarget tmpRenderTarget *ebiten.RenderTarget
ebitenTexture *ebiten.Image ebitenImage *ebiten.Image
} }
func (g *Game) Update(r *ebiten.RenderTarget) error { func (g *Game) Update(r *ebiten.RenderTarget) error {
@ -53,7 +53,7 @@ func (g *Game) Update(r *ebiten.RenderTarget) error {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
geo := ebiten.TranslateGeometry(15+float64(i)*(diff), 20) geo := ebiten.TranslateGeometry(15+float64(i)*(diff), 20)
clr := ebiten.ScaleColor(color.RGBA{0xff, 0xff, 0xff, 0x80}) clr := ebiten.ScaleColor(color.RGBA{0xff, 0xff, 0xff, 0x80})
if err := ebiten.DrawWholeImage(g.tmpRenderTarget, g.ebitenTexture, geo, clr); err != nil { if err := ebiten.DrawWholeImage(g.tmpRenderTarget, g.ebitenImage, geo, clr); err != nil {
return err return err
} }
} }
@ -72,7 +72,7 @@ func (g *Game) Update(r *ebiten.RenderTarget) error {
func main() { func main() {
g := new(Game) g := new(Game)
var err error var err error
g.ebitenTexture, _, err = ebitenutil.NewImageFromFile("images/ebiten.png", ebiten.FilterNearest) g.ebitenImage, _, err = ebitenutil.NewImageFromFile("images/ebiten.png", ebiten.FilterNearest)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -112,11 +112,11 @@ func (f *Field) flushLine(j int) bool {
return true return true
} }
func (f *Field) Draw(r *ebiten.RenderTarget, textures *Textures, geo ebiten.GeometryMatrix) { func (f *Field) Draw(r *ebiten.RenderTarget, images *Images, geo ebiten.GeometryMatrix) {
blocks := make([][]BlockType, len(f.blocks)) blocks := make([][]BlockType, len(f.blocks))
for i, blockCol := range f.blocks { for i, blockCol := range f.blocks {
blocks[i] = make([]BlockType, len(blockCol)) blocks[i] = make([]BlockType, len(blockCol))
copy(blocks[i], blockCol[:]) copy(blocks[i], blockCol[:])
} }
drawBlocks(r, textures, blocks, geo) drawBlocks(r, images, blocks, geo)
} }

View File

@ -22,7 +22,7 @@ import (
) )
func init() { func init() {
texturePaths["font"] = "images/blocks/font.png" imagePaths["font"] = "images/blocks/font.png"
} }
const charWidth = 8 const charWidth = 8
@ -32,8 +32,8 @@ func textWidth(str string) int {
return charWidth * len(str) return charWidth * len(str)
} }
func drawText(r *ebiten.RenderTarget, textures *Textures, str string, ox, oy, scale int, clr color.Color) { func drawText(r *ebiten.RenderTarget, images *Images, str string, ox, oy, scale int, clr color.Color) {
fontTextureId := textures.GetTexture("font") fontImageId := images.GetImage("font")
parts := []ebiten.ImagePart{} parts := []ebiten.ImagePart{}
locationX, locationY := 0, 0 locationX, locationY := 0, 0
@ -56,10 +56,10 @@ func drawText(r *ebiten.RenderTarget, textures *Textures, str string, ox, oy, sc
geoMat := ebiten.ScaleGeometry(float64(scale), float64(scale)) geoMat := ebiten.ScaleGeometry(float64(scale), float64(scale))
geoMat.Concat(ebiten.TranslateGeometry(float64(ox), float64(oy))) geoMat.Concat(ebiten.TranslateGeometry(float64(ox), float64(oy)))
clrMat := ebiten.ScaleColor(clr) clrMat := ebiten.ScaleColor(clr)
r.DrawImage(fontTextureId, parts, geoMat, clrMat) r.DrawImage(fontImageId, parts, geoMat, clrMat)
} }
func drawTextWithShadow(r *ebiten.RenderTarget, textures *Textures, str string, x, y, scale int, clr color.Color) { func drawTextWithShadow(r *ebiten.RenderTarget, images *Images, str string, x, y, scale int, clr color.Color) {
drawText(r, textures, str, x+1, y+1, scale, color.RGBA{0, 0, 0, 0x80}) drawText(r, images, str, x+1, y+1, scale, color.RGBA{0, 0, 0, 0x80})
drawText(r, textures, str, x, y, scale, clr) drawText(r, images, str, x, y, scale, clr)
} }

View File

@ -27,7 +27,7 @@ type Size struct {
} }
// TODO: Should they be global?? // TODO: Should they be global??
var texturePaths = map[string]string{} var imagePaths = map[string]string{}
var renderTargetSizes = map[string]Size{} var renderTargetSizes = map[string]Size{}
const ScreenWidth = 256 const ScreenWidth = 256
@ -42,7 +42,7 @@ type Game struct {
once sync.Once once sync.Once
sceneManager *SceneManager sceneManager *SceneManager
input *Input input *Input
textures *Textures images *Images
} }
func NewGame() *Game { func NewGame() *Game {
@ -54,16 +54,16 @@ func NewGame() *Game {
} }
func (game *Game) isInitialized() bool { func (game *Game) isInitialized() bool {
if game.textures == nil { if game.images == nil {
return false return false
} }
for name := range texturePaths { for name := range imagePaths {
if !game.textures.Has(name) { if !game.images.Has(name) {
return false return false
} }
} }
for name := range renderTargetSizes { for name := range renderTargetSizes {
if !game.textures.Has(name) { if !game.images.Has(name) {
return false return false
} }
} }
@ -72,12 +72,12 @@ func (game *Game) isInitialized() bool {
func (game *Game) Update(r *ebiten.RenderTarget) error { func (game *Game) Update(r *ebiten.RenderTarget) error {
game.once.Do(func() { game.once.Do(func() {
game.textures = NewTextures() game.images = NewImages()
for name, path := range texturePaths { for name, path := range imagePaths {
game.textures.RequestTexture(name, path) game.images.RequestImage(name, path)
} }
for name, size := range renderTargetSizes { for name, size := range renderTargetSizes {
game.textures.RequestRenderTarget(name, size) game.images.RequestRenderTarget(name, size)
} }
}) })
if !game.isInitialized() { if !game.isInitialized() {
@ -88,6 +88,6 @@ func (game *Game) Update(r *ebiten.RenderTarget) error {
SceneManager: game.sceneManager, SceneManager: game.sceneManager,
Input: game.input, Input: game.input,
}) })
game.sceneManager.Draw(r, game.textures) game.sceneManager.Draw(r, game.images)
return nil return nil
} }

View File

@ -24,7 +24,7 @@ import (
) )
func init() { func init() {
texturePaths["empty"] = "images/blocks/empty.png" imagePaths["empty"] = "images/blocks/empty.png"
} }
type GameScene struct { type GameScene struct {
@ -109,10 +109,10 @@ func (s *GameScene) Update(state *GameState) {
} }
} }
func (s *GameScene) Draw(r *ebiten.RenderTarget, textures *Textures) { func (s *GameScene) Draw(r *ebiten.RenderTarget, images *Images) {
r.Fill(color.White) r.Fill(color.White)
field := textures.GetTexture("empty") field := images.GetImage("empty")
w, h := field.Size() w, h := field.Size()
geoMat := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h)) geoMat := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h))
geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number? geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
@ -121,9 +121,9 @@ func (s *GameScene) Draw(r *ebiten.RenderTarget, textures *Textures) {
geoMat = ebiten.GeometryMatrixI() geoMat = ebiten.GeometryMatrixI()
geoMat.Concat(ebiten.TranslateGeometry(20, 20)) geoMat.Concat(ebiten.TranslateGeometry(20, 20))
s.field.Draw(r, textures, geoMat) s.field.Draw(r, images, geoMat)
if s.currentPiece != nil { if s.currentPiece != nil {
s.currentPiece.Draw(r, textures, 20, 20, s.currentPieceX, s.currentPieceY, s.currentPieceAngle) s.currentPiece.Draw(r, images, 20, 20, s.currentPieceX, s.currentPieceY, s.currentPieceAngle)
} }
} }

View File

@ -34,27 +34,27 @@ type nameSize struct {
size Size size Size
} }
type Textures struct { type Images struct {
texturePaths chan namePath imagePaths chan namePath
renderTargetSizes chan nameSize renderTargetSizes chan nameSize
textures map[string]*ebiten.Image images map[string]*ebiten.Image
renderTargets map[string]*ebiten.RenderTarget renderTargets map[string]*ebiten.RenderTarget
sync.RWMutex sync.RWMutex
} }
func NewTextures() *Textures { func NewImages() *Images {
textures := &Textures{ images := &Images{
texturePaths: make(chan namePath), imagePaths: make(chan namePath),
renderTargetSizes: make(chan nameSize), renderTargetSizes: make(chan nameSize),
textures: map[string]*ebiten.Image{}, images: map[string]*ebiten.Image{},
renderTargets: map[string]*ebiten.RenderTarget{}, renderTargets: map[string]*ebiten.RenderTarget{},
} }
go func() { go func() {
for { for {
textures.loopMain() images.loopMain()
} }
}() }()
return textures return images
} }
func loadImage(path string) (image.Image, error) { func loadImage(path string) (image.Image, error) {
@ -71,9 +71,9 @@ func loadImage(path string) (image.Image, error) {
return img, nil return img, nil
} }
func (t *Textures) loopMain() { func (i *Images) loopMain() {
select { select {
case p := <-t.texturePaths: case p := <-i.imagePaths:
name := p.name name := p.name
path := p.path path := p.path
go func() { go func() {
@ -85,11 +85,11 @@ func (t *Textures) loopMain() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.Lock() i.Lock()
defer t.Unlock() defer i.Unlock()
t.textures[name] = id i.images[name] = id
}() }()
case s := <-t.renderTargetSizes: case s := <-i.renderTargetSizes:
name := s.name name := s.name
size := s.size size := s.size
go func() { go func() {
@ -97,40 +97,40 @@ func (t *Textures) loopMain() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
t.Lock() i.Lock()
defer t.Unlock() defer i.Unlock()
t.renderTargets[name] = id i.renderTargets[name] = id
}() }()
} }
} }
func (t *Textures) RequestTexture(name string, path string) { func (i *Images) RequestImage(name string, path string) {
t.texturePaths <- namePath{name, path} i.imagePaths <- namePath{name, path}
} }
func (t *Textures) RequestRenderTarget(name string, size Size) { func (i *Images) RequestRenderTarget(name string, size Size) {
t.renderTargetSizes <- nameSize{name, size} i.renderTargetSizes <- nameSize{name, size}
} }
func (t *Textures) Has(name string) bool { func (i *Images) Has(name string) bool {
t.RLock() i.RLock()
defer t.RUnlock() defer i.RUnlock()
_, ok := t.textures[name] _, ok := i.images[name]
if ok { if ok {
return true return true
} }
_, ok = t.renderTargets[name] _, ok = i.renderTargets[name]
return ok return ok
} }
func (t *Textures) GetTexture(name string) *ebiten.Image { func (i *Images) GetImage(name string) *ebiten.Image {
t.RLock() i.RLock()
defer t.RUnlock() defer i.RUnlock()
return t.textures[name] return i.images[name]
} }
func (t *Textures) GetRenderTarget(name string) *ebiten.RenderTarget { func (i *Images) GetRenderTarget(name string) *ebiten.RenderTarget {
t.RLock() i.RLock()
defer t.RUnlock() defer i.RUnlock()
return t.renderTargets[name] return i.renderTargets[name]
} }

View File

@ -21,7 +21,7 @@ import (
) )
func init() { func init() {
texturePaths["blocks"] = "images/blocks/blocks.png" imagePaths["blocks"] = "images/blocks/blocks.png"
} }
type Angle int type Angle int
@ -138,7 +138,7 @@ const blockHeight = 10
const fieldBlockNumX = 10 const fieldBlockNumX = 10
const fieldBlockNumY = 20 const fieldBlockNumY = 20
func drawBlocks(r *ebiten.RenderTarget, textures *Textures, blocks [][]BlockType, geo ebiten.GeometryMatrix) { func drawBlocks(r *ebiten.RenderTarget, images *Images, blocks [][]BlockType, geo ebiten.GeometryMatrix) {
parts := []ebiten.ImagePart{} parts := []ebiten.ImagePart{}
for i, blockCol := range blocks { for i, blockCol := range blocks {
for j, block := range blockCol { for j, block := range blockCol {
@ -152,8 +152,8 @@ func drawBlocks(r *ebiten.RenderTarget, textures *Textures, blocks [][]BlockType
parts = append(parts, ebiten.ImagePart{dst, src}) parts = append(parts, ebiten.ImagePart{dst, src})
} }
} }
blocksTexture := textures.GetTexture("blocks") blocksImage := images.GetImage("blocks")
r.DrawImage(blocksTexture, parts, geo, ebiten.ColorMatrixI()) r.DrawImage(blocksImage, parts, geo, ebiten.ColorMatrixI())
} }
func (p *Piece) InitialPosition() (int, int) { func (p *Piece) InitialPosition() (int, int) {
@ -213,7 +213,7 @@ func (p *Piece) AbsorbInto(field *Field, x, y int, angle Angle) {
} }
} }
func (p *Piece) Draw(r *ebiten.RenderTarget, textures *Textures, fieldX, fieldY int, pieceX, pieceY int, angle Angle) { func (p *Piece) Draw(r *ebiten.RenderTarget, images *Images, fieldX, fieldY int, pieceX, pieceY int, angle Angle) {
size := len(p.blocks) size := len(p.blocks)
blocks := make([][]BlockType, size) blocks := make([][]BlockType, size)
for i := range p.blocks { for i := range p.blocks {
@ -230,5 +230,5 @@ func (p *Piece) Draw(r *ebiten.RenderTarget, textures *Textures, fieldX, fieldY
y := fieldY + pieceY*blockHeight y := fieldY + pieceY*blockHeight
geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y))) geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y)))
drawBlocks(r, textures, blocks, geoMat) drawBlocks(r, images, blocks, geoMat)
} }

View File

@ -29,7 +29,7 @@ func init() {
type Scene interface { type Scene interface {
Update(state *GameState) Update(state *GameState)
Draw(r *ebiten.RenderTarget, textures *Textures) Draw(r *ebiten.RenderTarget, images *Images)
} }
const transitionMaxCount = 20 const transitionMaxCount = 20
@ -60,18 +60,18 @@ func (s *SceneManager) Update(state *GameState) {
} }
} }
func (s *SceneManager) Draw(r *ebiten.RenderTarget, textures *Textures) { func (s *SceneManager) Draw(r *ebiten.RenderTarget, images *Images) {
if s.transitionCount == -1 { if s.transitionCount == -1 {
s.current.Draw(r, textures) s.current.Draw(r, images)
return return
} }
from := textures.GetRenderTarget("scene_manager_transition_from") from := images.GetRenderTarget("scene_manager_transition_from")
from.Clear() from.Clear()
s.current.Draw(from, textures) s.current.Draw(from, images)
to := textures.GetRenderTarget("scene_manager_transition_to") to := images.GetRenderTarget("scene_manager_transition_to")
to.Clear() to.Clear()
s.next.Draw(to, textures) s.next.Draw(to, images)
color := ebiten.ColorMatrixI() color := ebiten.ColorMatrixI()
ebiten.DrawWholeImage(r, from.Image(), ebiten.GeometryMatrixI(), color) ebiten.DrawWholeImage(r, from.Image(), ebiten.GeometryMatrixI(), color)

View File

@ -22,7 +22,7 @@ import (
) )
func init() { func init() {
texturePaths["background"] = "images/blocks/background.png" imagePaths["background"] = "images/blocks/background.png"
} }
type TitleScene struct { type TitleScene struct {
@ -40,43 +40,43 @@ func (s *TitleScene) Update(state *GameState) {
} }
} }
func (s *TitleScene) Draw(r *ebiten.RenderTarget, textures *Textures) { func (s *TitleScene) Draw(r *ebiten.RenderTarget, images *Images) {
drawTitleBackground(r, textures, s.count) drawTitleBackground(r, images, s.count)
drawLogo(r, textures, "BLOCKS") drawLogo(r, images, "BLOCKS")
message := "PRESS SPACE TO START" message := "PRESS SPACE TO START"
x := (ScreenWidth - textWidth(message)) / 2 x := (ScreenWidth - textWidth(message)) / 2
y := ScreenHeight - 48 y := ScreenHeight - 48
drawTextWithShadow(r, textures, message, x, y, 1, color.RGBA{0x80, 0, 0, 0xff}) drawTextWithShadow(r, images, message, x, y, 1, color.RGBA{0x80, 0, 0, 0xff})
} }
func drawTitleBackground(r *ebiten.RenderTarget, textures *Textures, c int) { func drawTitleBackground(r *ebiten.RenderTarget, images *Images, c int) {
const textureWidth = 32 const imageWidth = 32
const textureHeight = 32 const imageHeight = 32
backgroundTexture := textures.GetTexture("background") backgroundImage := images.GetImage("background")
parts := []ebiten.ImagePart{} parts := []ebiten.ImagePart{}
for j := -1; j < ScreenHeight/textureHeight+1; j++ { for j := -1; j < ScreenHeight/imageHeight+1; j++ {
for i := 0; i < ScreenWidth/textureWidth+1; i++ { for i := 0; i < ScreenWidth/imageWidth+1; i++ {
parts = append(parts, ebiten.ImagePart{ parts = append(parts, ebiten.ImagePart{
Dst: ebiten.Rect{float64(i * textureWidth), float64(j * textureHeight), textureWidth, textureHeight}, Dst: ebiten.Rect{float64(i * imageWidth), float64(j * imageHeight), imageWidth, imageHeight},
Src: ebiten.Rect{0, 0, textureWidth, textureHeight}, Src: ebiten.Rect{0, 0, imageWidth, imageHeight},
}) })
} }
} }
dx := (-c / 4) % textureWidth dx := (-c / 4) % imageWidth
dy := (c / 4) % textureHeight dy := (c / 4) % imageHeight
geo := ebiten.GeometryMatrixI() geo := ebiten.GeometryMatrixI()
geo.Concat(ebiten.TranslateGeometry(float64(dx), float64(dy))) geo.Concat(ebiten.TranslateGeometry(float64(dx), float64(dy)))
clr := ebiten.ColorMatrixI() clr := ebiten.ColorMatrixI()
r.DrawImage(backgroundTexture, parts, geo, clr) r.DrawImage(backgroundImage, parts, geo, clr)
} }
func drawLogo(r *ebiten.RenderTarget, textures *Textures, str string) { func drawLogo(r *ebiten.RenderTarget, images *Images, str string) {
scale := 4 scale := 4
textWidth := textWidth(str) * scale textWidth := textWidth(str) * scale
x := (ScreenWidth - textWidth) / 2 x := (ScreenWidth - textWidth) / 2
y := 32 y := 32
drawTextWithShadow(r, textures, str, x, y, scale, color.RGBA{0x00, 0x00, 0x80, 0xff}) drawTextWithShadow(r, images, str, x, y, scale, color.RGBA{0x00, 0x00, 0x80, 0xff})
} }

View File

@ -33,7 +33,7 @@ type Game struct {
count int count int
horizontalCount int horizontalCount int
verticalCount int verticalCount int
gophersTexture *ebiten.Image gophersImage *ebiten.Image
} }
func (g *Game) Update(r *ebiten.RenderTarget) error { func (g *Game) Update(r *ebiten.RenderTarget) error {
@ -51,7 +51,7 @@ func (g *Game) Update(r *ebiten.RenderTarget) error {
g.verticalCount++ g.verticalCount++
} }
w, h := g.gophersTexture.Size() w, h := g.gophersImage.Size()
geo := ebiten.TranslateGeometry(-float64(w)/2, -float64(h)/2) geo := ebiten.TranslateGeometry(-float64(w)/2, -float64(h)/2)
scaleX := 0.5 * math.Pow(1.05, float64(g.horizontalCount)) scaleX := 0.5 * math.Pow(1.05, float64(g.horizontalCount))
scaleY := 0.5 * math.Pow(1.05, float64(g.verticalCount)) scaleY := 0.5 * math.Pow(1.05, float64(g.verticalCount))
@ -60,14 +60,14 @@ func (g *Game) Update(r *ebiten.RenderTarget) error {
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
//clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180) //clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180)
clr := ebiten.ColorMatrixI() clr := ebiten.ColorMatrixI()
ebiten.DrawWholeImage(r, g.gophersTexture, geo, clr) ebiten.DrawWholeImage(r, g.gophersImage, geo, clr)
return nil return nil
} }
func main() { func main() {
g := new(Game) g := new(Game)
var err error var err error
g.gophersTexture, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest) g.gophersImage, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -31,13 +31,13 @@ const (
const mosaicRatio = 16 const mosaicRatio = 16
type Game struct { type Game struct {
gophersTexture *ebiten.Image gophersImage *ebiten.Image
gophersRenderTarget *ebiten.RenderTarget gophersRenderTarget *ebiten.RenderTarget
} }
func (g *Game) Update(r *ebiten.RenderTarget) error { func (g *Game) Update(r *ebiten.RenderTarget) error {
geo := ebiten.ScaleGeometry(1.0/mosaicRatio, 1.0/mosaicRatio) geo := ebiten.ScaleGeometry(1.0/mosaicRatio, 1.0/mosaicRatio)
ebiten.DrawWholeImage(g.gophersRenderTarget, g.gophersTexture, geo, ebiten.ColorMatrixI()) ebiten.DrawWholeImage(g.gophersRenderTarget, g.gophersImage, geo, ebiten.ColorMatrixI())
geo = ebiten.ScaleGeometry(mosaicRatio/2.0, mosaicRatio/2.0) geo = ebiten.ScaleGeometry(mosaicRatio/2.0, mosaicRatio/2.0)
ebiten.DrawWholeImage(r, g.gophersRenderTarget.Image(), geo, ebiten.ColorMatrixI()) ebiten.DrawWholeImage(r, g.gophersRenderTarget.Image(), geo, ebiten.ColorMatrixI())
@ -47,11 +47,11 @@ func (g *Game) Update(r *ebiten.RenderTarget) error {
func main() { func main() {
g := new(Game) g := new(Game)
var err error var err error
g.gophersTexture, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest) g.gophersImage, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
w, h := g.gophersTexture.Size() w, h := g.gophersImage.Size()
g.gophersRenderTarget, err = ebiten.NewRenderTarget(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest) g.gophersRenderTarget, err = ebiten.NewRenderTarget(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -29,12 +29,12 @@ const (
) )
type Game struct { type Game struct {
gophersTexture *ebiten.Image gophersImage *ebiten.Image
} }
func (g *Game) Update(r *ebiten.RenderTarget) error { func (g *Game) Update(r *ebiten.RenderTarget) error {
parts := []ebiten.ImagePart{} parts := []ebiten.ImagePart{}
w, h := g.gophersTexture.Size() w, h := g.gophersImage.Size()
for i := 0; i < h; i++ { for i := 0; i < h; i++ {
width := float64(w) + float64(i)*0.75 width := float64(w) + float64(i)*0.75
x := float64(h-i) * 0.75 / 2 x := float64(h-i) * 0.75 / 2
@ -48,14 +48,14 @@ func (g *Game) Update(r *ebiten.RenderTarget) error {
geo := ebiten.TranslateGeometry(-maxWidth/2, -float64(h)/2) geo := ebiten.TranslateGeometry(-maxWidth/2, -float64(h)/2)
geo.Concat(ebiten.ScaleGeometry(0.4, 0.4)) geo.Concat(ebiten.ScaleGeometry(0.4, 0.4))
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
r.DrawImage(g.gophersTexture, parts, geo, ebiten.ColorMatrixI()) r.DrawImage(g.gophersImage, parts, geo, ebiten.ColorMatrixI())
return nil return nil
} }
func main() { func main() {
g := new(Game) g := new(Game)
var err error var err error
g.gophersTexture, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest) g.gophersImage, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }