From 8b2890cd4fd7c137b964b7a7d9e3d0b66e4e73f0 Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Sat, 8 Feb 2020 19:25:36 -0800 Subject: [PATCH] batch bg --- gfx/gfx.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gfx/gfx.go b/gfx/gfx.go index 4acb255..9f2e713 100644 --- a/gfx/gfx.go +++ b/gfx/gfx.go @@ -65,7 +65,8 @@ func loadPicture(path string) (pixel.Picture, error) { } func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteBank) RenderState { - renderBackground(w) + batch := pixel.NewBatch(new(pixel.TrianglesData), nil) + renderBackground(w, batch) colors := teamColors(sNew.Teams) ctx := context{ @@ -86,9 +87,11 @@ func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteB var stars []pixel.Vec -func renderBackground(w *pixelgl.Window) { +func renderBackground(w *pixelgl.Window, batch *pixel.Batch) { w.Clear(colornames.Black) + batch.Clear() + if len(stars) == 0 { const numStars = 100 for i := 0; i < numStars; i++ { @@ -106,7 +109,9 @@ func renderBackground(w *pixelgl.Window) { im.Clear() } im.Circle(2, 0) - im.Draw(w) + im.Draw(batch) + + batch.Draw(w) } func renderRacers(ctx context, colors map[*game.Team]pixel.RGBA, pic pixel.Picture) {