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

View File

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