From 03fae7032a5cd653c0d64ec19758842e8b5ca7b0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 22 Jun 2013 02:42:14 +0900 Subject: [PATCH] Renamed methods --- example/game/rotating_image.go | 3 +-- example/game/sprites.go | 31 ++++++++++++++++------------- graphics/graphics.go | 11 +++++----- graphics/opengl/device.go | 5 +---- graphics/opengl/graphics_context.go | 7 ++++--- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/example/game/rotating_image.go b/example/game/rotating_image.go index 1812565cd..a31dc60e1 100644 --- a/example/game/rotating_image.go +++ b/example/game/rotating_image.go @@ -56,8 +56,7 @@ func (game *RotatingImage) Draw(g graphics.GraphicsContext, offscreen graphics.T centerY := float64(game.ScreenHeight()) / 2 geometryMatrix.Translate(centerX-tx/2, centerY-ty/2) - g.DrawTexture(game.ebitenTexture.ID, - graphics.Rect{0, 0, int(tx), int(ty)}, + g.DrawTexture(game.ebitenTexture, geometryMatrix, matrix.IdentityColor()) } diff --git a/example/game/sprites.go b/example/game/sprites.go index 2f79cb044..057f159a9 100644 --- a/example/game/sprites.go +++ b/example/game/sprites.go @@ -11,26 +11,26 @@ import ( ) type Sprite struct { - width int + width int height int - ch chan bool - x int - y int - vx int - vy int + ch chan bool + x int + y int + vx int + vy int } func NewSprite(screenWidth, screenHeight, width, height int) *Sprite { maxX := screenWidth - width maxY := screenHeight - height sprite := &Sprite{ - width: width, + width: width, height: height, - ch: make(chan bool), - x: rand.Intn(maxX), - y: rand.Intn(maxY), - vx: rand.Intn(2)*2 - 1, - vy: rand.Intn(2)*2 - 1, + ch: make(chan bool), + x: rand.Intn(maxX), + y: rand.Intn(maxY), + vx: rand.Intn(2)*2 - 1, + vy: rand.Intn(2)*2 - 1, } go sprite.update(screenWidth, screenHeight) return sprite @@ -61,6 +61,7 @@ func (sprite *Sprite) Update() { type Sprites struct { ebitenTexture graphics.Texture sprites []*Sprite + angle int } func NewSprites() *Sprites { @@ -102,6 +103,7 @@ func (game *Sprites) Update() { for _, sprite := range game.sprites { sprite.Update() } + game.angle++ } func (game *Sprites) Draw(g graphics.GraphicsContext, offscreen graphics.Texture) { @@ -120,8 +122,9 @@ func (game *Sprites) Draw(g graphics.GraphicsContext, offscreen graphics.Texture } locations = append(locations, location) } - g.DrawTextures(texture.ID, locations, - matrix.IdentityGeometry(), matrix.IdentityColor()) + geometryMatrix := matrix.IdentityGeometry() + g.DrawTextureParts(texture.ID, locations, + geometryMatrix, matrix.IdentityColor()) } func init() { diff --git a/graphics/graphics.go b/graphics/graphics.go index f77589f8a..b51cc220d 100644 --- a/graphics/graphics.go +++ b/graphics/graphics.go @@ -27,12 +27,13 @@ type TextureLocation struct { type GraphicsContext interface { Clear() Fill(color color.Color) - DrawTexture(textureId TextureID, - source Rect, - geometryMatrix matrix.Geometry, colorMatrix matrix.Color) - DrawTextures(textureId TextureID, + DrawTexture(texture Texture, + geometryMatrix matrix.Geometry, + colorMatrix matrix.Color) + DrawTextureParts(textureId TextureID, locations []TextureLocation, - geometryMatrix matrix.Geometry, colorMatrix matrix.Color) + geometryMatrix matrix.Geometry, + colorMatrix matrix.Color) SetOffscreen(textureId TextureID) } diff --git a/graphics/opengl/device.go b/graphics/opengl/device.go index d37408096..b39c23d84 100644 --- a/graphics/opengl/device.go +++ b/graphics/opengl/device.go @@ -55,10 +55,7 @@ func (device *Device) Update() { {0, scale, 0}, }, } - g.DrawTexture(device.offscreenTexture.ID, - graphics.Rect{ - 0, 0, device.screenWidth, device.screenHeight, - }, + g.DrawTexture(device.offscreenTexture, geometryMatrix, matrix.IdentityColor()) g.flush() } diff --git a/graphics/opengl/graphics_context.go b/graphics/opengl/graphics_context.go index db6d5b1d9..3e31d5767 100644 --- a/graphics/opengl/graphics_context.go +++ b/graphics/opengl/graphics_context.go @@ -66,14 +66,15 @@ func (context *GraphicsContext) DrawRect(x, y, width, height int, clr color.Colo } func (context *GraphicsContext) DrawTexture( - textureID graphics.TextureID, source graphics.Rect, + texture graphics.Texture, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { + source := graphics.Rect{0, 0, texture.Width, texture.Height} locations := []graphics.TextureLocation{{0, 0, source}} - context.DrawTextures(textureID, locations, + context.DrawTextureParts(texture.ID, locations, geometryMatrix, colorMatrix) } -func (context *GraphicsContext) DrawTextures( +func (context *GraphicsContext) DrawTextureParts( textureID graphics.TextureID, locations []graphics.TextureLocation, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {