mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
Refactoring
This commit is contained in:
parent
59921c5a34
commit
e6680eeda9
@ -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())
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user