-
-
Save faiface/e4d3a8b62953514ac32c778c4688fd6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image" | |
"image/draw" | |
"math/rand" | |
"golang.org/x/image/colornames" | |
"github.com/faiface/pixel" | |
"github.com/faiface/pixel/pixelgl" | |
) | |
func run() { | |
cfg := pixelgl.WindowConfig{ | |
Title: "Batch Test", | |
Bounds: pixel.R(0, 0, 1024, 768), | |
} | |
win, err := pixelgl.NewWindow(cfg) | |
if err != nil { | |
panic(err) | |
} | |
const n = 1e4 | |
img := image.NewRGBA(image.Rect(0, 0, 32, 32)) | |
draw.Draw(img, img.Bounds(), image.NewUniform(colornames.Red), image.ZP, draw.Src) | |
pic := pixel.PictureDataFromImage(img) | |
sprites := make([]*pixel.Sprite, n) | |
matrices := make([]pixel.Matrix, n) | |
for i := range sprites { | |
sprites[i] = pixel.NewSprite(pic, pic.Bounds()) | |
matrices[i] = pixel.IM.Moved(pixel.V( | |
rand.Float64()*win.Bounds().W(), | |
rand.Float64()*win.Bounds().H(), | |
)) | |
} | |
batch := pixel.NewBatch(&pixel.TrianglesData{}, pic) | |
for !win.Closed() { | |
win.Clear(colornames.White) | |
batch.Clear() | |
for i := range sprites { | |
sprites[i].Draw(batch, matrices[i]) | |
} | |
batch.Draw(win) | |
win.Update() | |
} | |
} | |
func main() { | |
pixelgl.Run(run) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment