Refactoring

This commit is contained in:
Hajime Hoshi 2013-10-11 22:17:49 +09:00
parent 59921c5a34
commit e6680eeda9
2 changed files with 27 additions and 25 deletions

View File

@ -33,8 +33,8 @@ import (
type Rects struct {
rectTexture graphics.Texture
rectTextureInited bool
rectsTexture graphics.Texture
rectsTextureInited bool
offscreen graphics.Texture
offscreenInited bool
rectBounds *graphics.Rect
rectColor *color.RGBA
}
@ -42,7 +42,7 @@ type Rects struct {
func New() *Rects {
return &Rects{
rectTextureInited: false,
rectsTextureInited: false,
offscreenInited: false,
rectBounds: &graphics.Rect{},
rectColor: &color.RGBA{},
}
@ -50,7 +50,7 @@ func New() *Rects {
func (game *Rects) Init(tf graphics.TextureFactory) {
game.rectTexture = tf.NewTexture(16, 16)
game.rectsTexture = tf.NewTexture(256, 240)
game.offscreen = tf.NewTexture(256, 240)
}
func (game *Rects) Update(context ebiten.GameContext) {
@ -99,17 +99,17 @@ func (game *Rects) Draw(g graphics.Context) {
game.rectTextureInited = true
}
g.SetOffscreen(game.rectsTexture.ID())
if !game.rectsTextureInited {
g.SetOffscreen(game.offscreen.ID())
if !game.offscreenInited {
g.Fill(&color.RGBA{0, 0, 0, 255})
game.rectsTextureInited = true
game.offscreenInited = true
}
g.DrawTexture(game.rectTexture.ID(),
game.rectGeometryMatrix(),
game.rectColorMatrix())
g.SetOffscreen(g.Screen().ID())
g.DrawTexture(game.rectsTexture.ID(),
g.DrawTexture(game.offscreen.ID(),
matrix.IdentityGeometry(),
matrix.IdentityColor())
}

View File

@ -102,19 +102,21 @@ func (game *Sprites) Init(tf graphics.TextureFactory) {
if game.ebitenTexture, err = tf.NewTextureFromImage(img); err != nil {
panic(err)
}
}
func (game *Sprites) Update(context ebiten.GameContext) {
if game.sprites == nil {
game.sprites = []*Sprite{}
for i := 0; i < 100; i++ {
// TODO: fix
sprite := newSprite(
256,
240,
context.ScreenWidth(),
context.ScreenHeight(),
game.ebitenTexture.Width(),
game.ebitenTexture.Height())
game.sprites = append(game.sprites, sprite)
}
}
}
func (game *Sprites) Update(context ebiten.GameContext) {
for _, sprite := range game.sprites {
sprite.Update()
}