From 30f59e979861db5dfc3a977d25b99f17f215fb8d Mon Sep 17 00:00:00 2001 From: faiface Date: Fri, 26 May 2017 14:04:44 +0200 Subject: [PATCH] update 05 guide code --- .../05_drawing_efficiently_with_batch/main.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/guide/05_drawing_efficiently_with_batch/main.go b/guide/05_drawing_efficiently_with_batch/main.go index 80ba261..3cb596f 100644 --- a/guide/05_drawing_efficiently_with_batch/main.go +++ b/guide/05_drawing_efficiently_with_batch/main.go @@ -46,8 +46,8 @@ func run() { batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet) var treesFrames []pixel.Rect - for x := spritesheet.Bounds().Min.X(); x < spritesheet.Bounds().Max.X(); x += 32 { - for y := spritesheet.Bounds().Min.Y(); y < spritesheet.Bounds().Max.Y(); y += 32 { + for x := spritesheet.Bounds().Min.X; x < spritesheet.Bounds().Max.X; x += 32 { + for y := spritesheet.Bounds().Min.Y; y < spritesheet.Bounds().Max.Y; y += 32 { treesFrames = append(treesFrames, pixel.R(x, y, x+32, y+32)) } } @@ -69,28 +69,27 @@ func run() { dt := time.Since(last).Seconds() last = time.Now() - cam := pixel.IM.Scaled(camPos, camZoom).Moved(win.Bounds().Center() - camPos) + cam := pixel.IM.Scaled(camPos, camZoom).Moved(win.Bounds().Center().Sub(camPos)) win.SetMatrix(cam) if win.Pressed(pixelgl.MouseButtonLeft) { tree := pixel.NewSprite(spritesheet, treesFrames[rand.Intn(len(treesFrames))]) mouse := cam.Unproject(win.MousePosition()) - tree.SetMatrix(pixel.IM.Scaled(0, 4).Moved(mouse)) - tree.Draw(batch) + tree.Draw(batch, pixel.IM.Scaled(pixel.ZV, 4).Moved(mouse)) } if win.Pressed(pixelgl.KeyLeft) { - camPos -= pixel.X(camSpeed * dt) + camPos.X -= camSpeed * dt } if win.Pressed(pixelgl.KeyRight) { - camPos += pixel.X(camSpeed * dt) + camPos.X += camSpeed * dt } if win.Pressed(pixelgl.KeyDown) { - camPos -= pixel.Y(camSpeed * dt) + camPos.Y -= camSpeed * dt } if win.Pressed(pixelgl.KeyUp) { - camPos += pixel.Y(camSpeed * dt) + camPos.Y += camSpeed * dt } - camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y()) + camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y) win.Clear(colornames.Forestgreen) batch.Draw(win)