Remove Texture.Width()/Height()

This commit is contained in:
Hajime Hoshi 2013-10-16 23:20:07 +09:00
parent 5679120f29
commit fd0ba69f0b
5 changed files with 24 additions and 11 deletions

View File

@ -9,6 +9,11 @@ import (
"os" "os"
) )
const (
ebitenTextureWidth = 57
ebitenTextureHeight = 26
)
type Monochrome struct { type Monochrome struct {
ebitenTexture graphics.Texture ebitenTexture graphics.Texture
ch chan bool ch chan bool
@ -89,8 +94,8 @@ func (game *Monochrome) Update(context ebiten.GameContext) {
<-game.ch <-game.ch
game.geometryMatrix = matrix.IdentityGeometry() game.geometryMatrix = matrix.IdentityGeometry()
tx := context.ScreenWidth()/2 - game.ebitenTexture.Width()/2 tx := context.ScreenWidth()/2 - ebitenTextureWidth/2
ty := context.ScreenHeight()/2 - game.ebitenTexture.Height()/2 ty := context.ScreenHeight()/2 - ebitenTextureHeight/2
game.geometryMatrix.Translate(float64(tx), float64(ty)) game.geometryMatrix.Translate(float64(tx), float64(ty))
} }

View File

@ -20,10 +20,10 @@ type Rects struct {
} }
const ( const (
rectTextureWidth = 16 rectTextureWidth = 16
rectTextureHeight = 16 rectTextureHeight = 16
offscreenWidth = 256 offscreenWidth = 256
offscreenHeight = 240 offscreenHeight = 240
) )
func New() *Rects { func New() *Rects {

View File

@ -10,6 +10,11 @@ import (
"os" "os"
) )
const (
ebitenTextureWidth = 57
ebitenTextureHeight = 26
)
type Rotating struct { type Rotating struct {
ebitenTexture graphics.Texture ebitenTexture graphics.Texture
x int x int
@ -40,7 +45,7 @@ func (game *Rotating) Update(context ebiten.GameContext) {
game.x++ game.x++
game.geometryMatrix = matrix.IdentityGeometry() game.geometryMatrix = matrix.IdentityGeometry()
tx, ty := float64(game.ebitenTexture.Width()), float64(game.ebitenTexture.Height()) tx, ty := float64(ebitenTextureWidth), float64(ebitenTextureHeight)
game.geometryMatrix.Translate(-tx/2, -ty/2) game.geometryMatrix.Translate(-tx/2, -ty/2)
game.geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(ebiten.FPS*10)) game.geometryMatrix.Rotate(float64(game.x) * 2 * math.Pi / float64(ebiten.FPS*10))
game.geometryMatrix.Translate(tx/2, ty/2) game.geometryMatrix.Translate(tx/2, ty/2)

View File

@ -10,6 +10,11 @@ import (
"time" "time"
) )
const (
ebitenTextureWidth = 57
ebitenTextureHeight = 26
)
type Sprite struct { type Sprite struct {
width int width int
height int height int
@ -90,8 +95,8 @@ func (game *Sprites) Update(context ebiten.GameContext) {
sprite := newSprite( sprite := newSprite(
context.ScreenWidth(), context.ScreenWidth(),
context.ScreenHeight(), context.ScreenHeight(),
game.ebitenTexture.Width(), ebitenTextureWidth,
game.ebitenTexture.Height()) ebitenTextureHeight)
game.sprites = append(game.sprites, sprite) game.sprites = append(game.sprites, sprite)
} }
} }
@ -112,7 +117,7 @@ func (game *Sprites) Draw(g graphics.Context) {
LocationX: sprite.x, LocationX: sprite.x,
LocationY: sprite.y, LocationY: sprite.y,
Source: graphics.Rect{ Source: graphics.Rect{
0, 0, texture.Width(), texture.Height(), 0, 0, ebitenTextureWidth, ebitenTextureHeight,
}, },
} }
locations = append(locations, location) locations = append(locations, location)

View File

@ -39,8 +39,6 @@ type TextureFactory interface {
type Texture interface { type Texture interface {
ID() TextureID ID() TextureID
Width() int
Height() int
} }
type TextureID int type TextureID int