diff --git a/ebitenutil/gif.go b/ebitenutil/gif.go index aac7b1cbd..fcb4f0d0d 100644 --- a/ebitenutil/gif.go +++ b/ebitenutil/gif.go @@ -18,7 +18,7 @@ import ( "github.com/hajimehoshi/ebiten" "image" "image/color" - //"image/color/palette" + "image/color/palette" "image/draw" "image/gif" "io" @@ -35,7 +35,7 @@ type recorder struct { wg sync.WaitGroup } -var palette = color.Palette{ +var cheapPalette = color.Palette{ color.RGBA{0x00, 0x00, 0x00, 0xff}, color.RGBA{0xff, 0x00, 0x00, 0xff}, color.RGBA{0x00, 0xff, 0x00, 0xff}, @@ -55,6 +55,13 @@ func (r *recorder) delay() int { return delay } +func (r *recorder) palette() color.Palette { + if 1 < (r.frameNum-1)/r.skips+1 { + return cheapPalette + } + return palette.Plan9 +} + func (r *recorder) update(screen *ebiten.Image) error { if err := r.inner(screen); err != nil { return err @@ -74,7 +81,7 @@ func (r *recorder) update(screen *ebiten.Image) error { s := image.NewNRGBA(screen.Bounds()) draw.Draw(s, s.Bounds(), screen, screen.Bounds().Min, draw.Src) - img := image.NewPaletted(s.Bounds(), palette) + img := image.NewPaletted(s.Bounds(), r.palette()) f := r.currentFrame / r.skips r.wg.Add(1) go func() { @@ -122,7 +129,7 @@ func RecordScreenAsGIF(update func(*ebiten.Image) error, out io.Writer, frameNum inner: update, writer: out, frameNum: frameNum, - skips: 4, + skips: 5, } return r.update } diff --git a/example/blocks/main.go b/example/blocks/main.go index 3676d60e0..13b8f7cee 100644 --- a/example/blocks/main.go +++ b/example/blocks/main.go @@ -42,7 +42,8 @@ func main() { } game := blocks.NewGame() - if err := ebiten.Run(game.Update, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)"); err != nil { + update := game.Update + if err := ebiten.Run(update, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)"); err != nil { log.Fatal(err) } }