From 748f605bffed1309e8dfaf95110c5883ac23dca7 Mon Sep 17 00:00:00 2001 From: Jalen Winslow Date: Tue, 23 Jan 2018 06:06:35 -0700 Subject: [PATCH] animated sprite --- main.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1529f3b..7e90272 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,8 @@ func run() { var now int64 var dt int64 + frameCounter := 0 + // Game Loop for !win.Closed() { now = time.Now().UnixNano() @@ -126,23 +128,33 @@ func run() { //mouse := cam.Unproject(win.MousePosition()) + frameCounter += 1 + if frameCounter >= 3 { + frameCounter = 0 + } speed := 10.0 + sprFrame := 0 if win.Pressed(pixelgl.KeyA) { //left + sprFrame = 6 playerX -= speed - Sprite.Set(spritesheet, spritesFrames[6]) + //Sprite.Set(spritesheet, spritesFrames[sprFrame+frameCounter]) } if win.Pressed(pixelgl.KeyD) { //Right + sprFrame = 3 playerX += speed - Sprite.Set(spritesheet, spritesFrames[3]) + //Sprite.Set(spritesheet, spritesFrames[3]) } if win.Pressed(pixelgl.KeyS) { //Down + sprFrame = 9 playerY -= speed - Sprite.Set(spritesheet, spritesFrames[9]) + //Sprite.Set(spritesheet, spritesFrames[9]) } if win.Pressed(pixelgl.KeyW) { //up + sprFrame = 0 playerY += speed - Sprite.Set(spritesheet, spritesFrames[0]) + //Sprite.Set(spritesheet, spritesFrames[0]) } + Sprite.Set(spritesheet, spritesFrames[sprFrame+frameCounter]) camPos.X = playerX camPos.Y = playerY camZoom *= math.Pow(camZoomSpeed, win.MouseScroll().Y)