diff --git a/example/game/rects/rects.go b/example/game/rects/rects.go index 27185e7cb..1442f0486 100644 --- a/example/game/rects/rects.go +++ b/example/game/rects/rects.go @@ -31,26 +31,26 @@ import ( ) type Rects struct { - rectTexture graphics.Texture - rectTextureInited bool - rectsTexture graphics.Texture - rectsTextureInited bool - rectBounds *graphics.Rect - rectColor *color.RGBA + rectTexture graphics.Texture + rectTextureInited bool + offscreen graphics.Texture + offscreenInited bool + rectBounds *graphics.Rect + rectColor *color.RGBA } func New() *Rects { return &Rects{ - rectTextureInited: false, - rectsTextureInited: false, - rectBounds: &graphics.Rect{}, - rectColor: &color.RGBA{}, + rectTextureInited: false, + offscreenInited: false, + rectBounds: &graphics.Rect{}, + rectColor: &color.RGBA{}, } } 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()) } diff --git a/example/game/sprites/sprites.go b/example/game/sprites/sprites.go index 2dcdc3fa3..e1d0a8a60 100644 --- a/example/game/sprites/sprites.go +++ b/example/game/sprites/sprites.go @@ -102,19 +102,21 @@ func (game *Sprites) Init(tf graphics.TextureFactory) { if game.ebitenTexture, err = tf.NewTextureFromImage(img); err != nil { panic(err) } - game.sprites = []*Sprite{} - for i := 0; i < 100; i++ { - // TODO: fix - sprite := newSprite( - 256, - 240, - game.ebitenTexture.Width(), - game.ebitenTexture.Height()) - game.sprites = append(game.sprites, sprite) - } } func (game *Sprites) Update(context ebiten.GameContext) { + if game.sprites == nil { + game.sprites = []*Sprite{} + for i := 0; i < 100; i++ { + sprite := newSprite( + context.ScreenWidth(), + context.ScreenHeight(), + game.ebitenTexture.Width(), + game.ebitenTexture.Height()) + game.sprites = append(game.sprites, sprite) + } + } + for _, sprite := range game.sprites { sprite.Update() }